Created
June 20, 2013 16:01
-
-
Save flashfabrixx/5824103 to your computer and use it in GitHub Desktop.
Setting authorization header in AFNetworking with special characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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