2013-07-15 57 views
3

我正在使用RestKit 0.2,並且出現以下錯誤。RestKit 0.2錯誤'(400-499)中的預期狀態碼,得到200'

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作爲服務器端。我可以通過Google Chrome瀏覽器獲取json數據,並且可以看到Content-Type的響應是Chrome中的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}。

謝謝。

+0

顯示您的映射和響應描述符。狀態碼被設置在那裏,所以某些東西不排隊。 – Wain

+1

@謝謝,我發現這是一個映射問題。請看看https://github.com/RestKit/RestKit/issues/1501 –

回答

5

當定義的響應描述符的請求,則需要如果期望與HTTP狀態代碼的響應,以設​​置狀態代碼到RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)的2xx

實施例:

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

更新:

請確保響應描述符的pathPattern匹配請求pa日。否則,RestKit將使用錯誤響應描述符(如果您定義它)​​,並期望使用不同狀態代碼的響應。

+0

謝謝!我的問題是由於你提到的PathPattern不匹配造成的。解決這個問題解決了我的情況。 – kleezy

相關問題