我尝试使用 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。