Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created September 11, 2010 07:51
Show Gist options
  • Save wjessop/574965 to your computer and use it in GitHub Desktop.
Save wjessop/574965 to your computer and use it in GitHub Desktop.
+ (Response *)get:(NSString *)url withUser:(NSString *)user andPassword:(NSString *)password {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithUrl:[NSURL URLWithString:url] andMethod:@"GET"];
return [self sendRequest:request withUser:user andPassword:password];
}
// to:
+ (Response *)get:(NSString *)url withUser:(NSString *)user andPassword:(NSString *)password {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithUrl:[NSURL URLWithString:url] andMethod:@"GET"];
for (NSDictionary *header in requestHeaders)
[request addValue:[header objectForKey:@"value"] forHTTPHeaderField:[header objectForKey:@"name"]];
return [self sendRequest:request withUser:user andPassword:password];
}
@caius
Copy link

caius commented Sep 11, 2010

-[NSURLRequest setAllHTTPHeaderFields:] saves you the for loop.

@wjessop
Copy link
Author

wjessop commented Sep 11, 2010

At the expense of overwriting existing headers, such as any previously set "Accepts" header, but this may be OK for what you are doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment