Skip to content

Instantly share code, notes, and snippets.

@flashfabrixx
Created June 20, 2013 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flashfabrixx/5824103 to your computer and use it in GitHub Desktop.
Save flashfabrixx/5824103 to your computer and use it in GitHub Desktop.
Setting authorization header in AFNetworking with special characters
// Override the following method in AFHTTPClient.m
- (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password {
CFHTTPMessageRef dummyRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)@"GET", (__bridge CFURLRef)[NSURL URLWithString:@"http://yourdummyurl.com"], kCFHTTPVersion1_1);
if (dummyRequest) {
CFHTTPMessageAddAuthentication(dummyRequest, nil, (__bridge CFStringRef)username, (__bridge CFStringRef)password,kCFHTTPAuthenticationSchemeBasic, FALSE);
CFStringRef authorizationString = CFHTTPMessageCopyHeaderFieldValue(dummyRequest, CFSTR("Authorization"));
if (authorizationString) {
NSLog(@"Authorization: %@", authorizationString);
[self setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"%@", authorizationString]];
CFRelease(authorizationString);
}
CFRelease(dummyRequest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment