RestKit:请求失败时获取HTTP状态码
我在iOS应用程序中使用RestKit,我需要对某些HTTP错误代码进行特殊处理。 如何在request:didFailLoadWithError:
检查响应HTTP状态代码request:didFailLoadWithError:
在NSError
的userInfo
字典中是否有一些条目?
我在RKRequestDelegate
文档中找不到任何东西。
这是委托方法的接口:
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error
对于使用新版RESTkit和objectManager的用户,可以从RKObjectRequestOperation
获取状态RKObjectRequestOperation
:
operation.HTTPRequestOperation.response.statusCode
事实certificatedidFailLoadWithError:
不会被HTTP错误调用。 request:didLoadResponse:
方法仍然被调用HTTP错误,所以响应(和因此的状态代码)是可用的。
RKResponse
上的statusCode
属性适用于我:
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error { switch ([[objectLoader response] statusCode]) { case 409: ... }