RestKit 0.2错误'预期状态代码在(400-499),得到200'

时间:2013-07-15 03:26:05

标签: ios restkit-0.20

我正在使用RestKit 0.2,我收到以下错误。

E restkit.network:RKObjectRequestOperation.m:237 GET 'http://some.url.com/o/3134' (200 OK / 0 objects) [request=3.2563s mapping=0.0000s total=3.2955s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (400-499), got 200" UserInfo=0x87712e0 {NSLocalizedRecoverySuggestion={"d":"2013-07-15T02:30:00.000Z","t":16.1,"at":13.8}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://some.url.com/o/3134>, NSErrorFailingURLKey=http://some.url.com/o/3134, NSLocalizedDescription=Expected status code in (400-499), got 200, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x9647260>}

我使用nodejs并作为服务器端解析。我可以使用谷歌浏览器获取json数据,我可以看到Chrome的内容类型响应是application / json。

但是当我使用RestKit时,我得到了关于&#39;预期状态代码(400-499),得到200&#39;,我认为200很好,为什么RestKit期望400 - 499而不是200?我也可以在错误消息中看到json对象。这是{&#34; d&#34;:&#34; 2013-07-15T02:30:00.000Z&#34;,&#34; t&#34;:16.1,&#34; at&#34;: 13.8}。

感谢。

1 个答案:

答案 0 :(得分:6)

当您为请求定义响应描述符时,如果您希望响应http状态代码为2xx,则需要将状态代码设置为RKStatusCodeIndexSetForClass( RKStatusCodeClassSuccessful

示例:

[RKResponseDescriptor responseDescriptorWithMapping:yourMapping method:RKRequestMethodAny pathPattern:yourPattern keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

<强>更新

确保响应描述符的pathPattern与请求路径匹配。否则,RestKit将使用错误响应描述符(如果您定义它)​​,并期望具有不同状态代码的响应。