我尝试使用AFHTTPRequestOperation获取自定义标头密钥,我尝试使用allHeaderFields但没有,这里是标头响应
HTTP/1.1 302 Moved Temporarily
Server nginx
Date Tue, 19 Feb 2013 16:38:29 GMT
Content-Type text/html
Transfer-Encoding chunked
Connection keep-alive
Set-Cookie AUTH-ID="fjArrnmlyNMU9kfIu38Oc0LS451Y/UaMn0rb5sKj46CxmfJj8y8yr8CfwOewItFY"; HTTPOnly
X-AUTH-TOKEN mfy+426BNZdq1h92As3oXdZbf2iOI7wV7EOEUMAV3hAqtY7cOnWvA4df7h6RfjeD
Location /home.php
我像这样使用AFHTTPRequestOperation
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *headerData = [[operation response] allHeaderFields];
if ([headerData objectForKey:@"X-AUTH-TOKEN"] != nil)
token = [headerData objectForKey:@"X-AUTH-TOKEN"];
NSLog(@"headers = %@", headerData);
NSLog(@"token = %@", token);
...
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
...
}];
但是X-AUTH-TOKEN键没有出现在标题NSLog中,我确定标题键存在,因为我使用Charles代理进行调试,Charles向我显示X-AUTH-TOKEN键。也许302状态代码是问题,任何人都可以帮助我吗? 感谢。
[编辑]当我尝试显示响应的状态代码时,它是200。
答案 0 :(得分:-1)
解决使用AFURLConnectionOperation的一些调整来拦截重定向响应。