【发布时间】:2013-09-19 06:21:08
【问题描述】:
我在 iOS 应用程序中从 ASIHTTPRequest 切换到 AFNetworking。
RF2616 (HTTP/1.1)通过“状态代码”和“原因短语”的组合定义了一个“状态行”。有时服务器会在这个“原因短语”中添加一些特定信息,我发现 ASIHTTPRequest 允许我通过以下方式轻松访问它非常方便
ASIHTTPRequest *request = ...;
NSString *reason = request.responseStatusMessage;
我的问题是我找不到任何方法来使用AFHTTPRequestOperation
NSMutableURLRequest *request = ...;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
在操作的完成/失败块中,我可以通过以下方式获取状态代码:
int statusCode = [operation.response statusCode];
但我找不到“原因短语”的获取位置。
StackOverflow 上的一些答案表明它将位于 [operation.response allHeaderFields] 的条目之一中,但事实并非如此。
这个问题的答案Can I access "Reason Phrase" from the HTTP Status-Line in NSHTTPURLResponse >> 建议更改服务器的行为方式,但这并不总是可用的选项。
有什么想法吗?
【问题讨论】:
-
您使用的是什么 URL?
标签: ios afnetworking asihttprequest http-1.1 rfc2616