我尝试使用仅限应用程序的身份验证 API对 twitter API 进行身份验证调用
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:20.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"Some App Name" forHTTPHeaderField:@"User-Agent"];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
[request setHTTPBody:[@"grant_type=client_credentials" dataUsingEncoding:NSUTF8StringEncoding]];
有趣的是,没有为HTTPHeaderField @“Authorization”设置 authValue。因此,我的电话当然会失败。所有其他标头字段均已正确设置。
我检查它
NSLog(@"Authorization, %@, %@", [request valueForHTTPHeaderField:@"Authorization"], authValue);
它返回@"Authorization, (null), theCorrectStuff
为什么会这样?我应该可以立即设置它,还是我错过了什么?
感谢您的时间和考虑,费边