【发布时间】:2013-08-31 12:42:23
【问题描述】:
我尝试使用 Application only Authentication 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]];
有趣的是,authValue 没有为 HTTPHeaderField @"Authorization" 设置。因此,我的电话当然会失败。所有其他标头字段均已正确设置。
我检查一下
NSLog(@"Authorization, %@, %@", [request valueForHTTPHeaderField:@"Authorization"], authValue);
返回@"Authorization, (null), theCorrectStuff
为什么会这样?我应该可以立即设置它,还是我错过了什么?
感谢您的时间和考虑, 费边
【问题讨论】:
标签: objective-c twitter-oauth nsurlrequest http-authentication nsmutableurlrequest