I\'m having a difficulty transforming this curl command for my Objective C Code:
curl -u 0ef106c78146a23becba9105d1e:X -H \"Accept: application/json\" -H \"C
First of all, you don't need the colon in the HTTP header field name.
Second, you're doing the HTTP authentication wrong. You need to concat your username and password, username:password
and Base64 encode the concatenated string data.
Use the base64 value as value for the header field Authorization
, use the code below and drop in a Base 64 encoding implementation.
// snip
NSMutableUrlRequest* theRequest = [NSMutableUrlRequest ...]
[MyClass httpAuthorizeRequest:theRequest withUsername:@"someuser" andPassword:@"mysecret"];
// snip
+ (void)httpAuthorizeRequest:(NSMutableURLRequest*)request withUsername:(NSString*)username andPassword:(NSString*)password
{
NSString* authorizationToken = [[NSString stringWithFormat:@"%@:%@", username, password] base64Representation];
[request setValue:[NSString stringWithFormat:@"Basic %@", authorizationToken] forHTTPHeaderField:@"Authorization"];
}