gpt4 book ai didi

ios - RestKit 0.2 错误 'Expected status code in (400-499), got 200'

转载 作者:可可西里 更新时间:2023-11-01 05:30:14 24 4
gpt4 key购买 nike

我正在使用 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和restify作为服务端。我可以使用谷歌浏览器获取 json 数据,我可以在 Chrome 中看到响应的 Content-Type 是 application/json 。

但是当我使用 RestKit 时,我收到关于“预期状态代码在 (400-499) 中,得到 200”的错误,我认为 200 没问题,为什么 RestKit 期望 400 - 499 而不是 200?我也可以在错误消息中看到 json 对象。这是 {"d":"2013-07-15T02:30:00.000Z","t":16.1,"at":13.8}。

谢谢。

最佳答案

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

例子:

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

更新:

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

关于ios - RestKit 0.2 错误 'Expected status code in (400-499), got 200',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17646318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com