Problem with NSString and NSMutableURLRequest
I am having problems adding a title to NSMutableURlRequest, the problem is that when I add the title below "Authorization" it doesn't appear. However, if I replace my "auth" instance variable below with the static string exp (@ "asdadsadsadga") the heading "Authorization" appears. I'm pretty lost on this point.
NSURL *url = [NSURL URLWithString:@"https://www.google.com/analytics/feeds/accounts/default"];
NSMutableURLRequest *profileRequest = [NSMutableURLRequest requestWithURL:url];
NSLog(auth); //prints correctly
NSString *authString = [NSString stringWithFormat:@"GoogleLogin Auth=%@", auth];
[profileRequest addValue:authString forHTTPHeaderField:@"Authorization"];
NSDictionary *allheaders = [profileRequest allHTTPHeaderFields];
for (id key in allheaders)
{
//Nothing prints
NSLog(@"key: %@, value: %@", key, [allheaders objectForKey:key]);
}
NSLog(auth); //Prints correctly
First, replace NSLog (auth) with NSLog (@ "% @", auth). The first one is dangerous and may show some of what is happening here. You should also try adding early on:
auth = @"asdasdasdad";
You should also try to just dump all headers directly:
NSLog(@"%@", [profileRequest allHTTPHeaderFields];
It can shed some light. I suspect the problem is with your auth variable, possibly memory management related, not NSMutableURLRequest.
a source to share
The code you are using to generate the base64Encoded string is not working.
Try using the method outlined at the bottom of the page: http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
a source to share