我在向 NSMutableURlRequest 添加标头时遇到问题,问题是当我在“授权”下方添加标头时,它没有显示出来。但是,如果我用静态字符串 exp (@"asdadsadsadga") 替换下面的实例变量“auth”,则会显示“Authorization”标题。在这一点上我很迷茫。
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