Reputation: 1006
I am experiencing the weirdest error while using RestKit. Here's the localized description of the error -
Expected content type {(
"application/json",
"text/html",
"text/plain",
"application/x-www-form-urlencoded"
)}, got {application/json}
As you can see, I am expecting "application/json" as a content type, and the server is returning application/json. I have no idea why I am getting this error!
The detailed error is here --
2015-02-19 11:24:43.234 MyProject[62944:10754151] E restkit.network:RKObjectRequestOperation.m:213 POST 'https://ipaddress/api/v1.0/user/verify' (200 OK / 0 objects) [request=0.1408s mapping=0.0000s total=0.1428s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
"application/json",
"text/html",
"text/plain",
"application/x-www-form-urlencoded"
)}, got {application/json" UserInfo=0x7f9c49db4930 {NSLocalizedRecoverySuggestion={"user_id":"3749f17f647c4ee1a9ee9d75c5f49f7e","domain":"domain","device_id":"2751029764","access_token":"589134b447974320b2d494a491e8226a","access_token_expiration":2181237828314,"refresh_token":"cb06c038be7b4f7c930de1fcb3f2017a"}, NSErrorFailingURLKey=https://ipaddress/api/v1.0/user/verify, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x7f9c49def0c0> { URL: https://ipaddress/api/v1.0/user/verify }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7f9c49f567a0> { URL: https://ipaddress/api/v1.0/user/verify } { status code: 200, headers {
"Baseline-Request-Id" = 30f91b50;
Connection = "keep-alive";
"Content-Length" = 230;
"Content-Type" = "{application/json, q=1000}";
Date = "Thu, 19 Feb 2015 19:23:48 GMT";
Server = "nginx/1.6.2";
} }, NSLocalizedDescription=Expected content type {(
"application/json",
"text/html",
"text/plain",
"application/x-www-form-urlencoded"
)}, got {application/json}
Update --
After some debugging, I found out that the problem lies in the value of "Content-Type" I am getting in the response. As you can see in the example above, the value is "{application/json, q=1000}
" instead of "application/json
". RestKit, for some reason, is reading it as "{application/json
" (omitting the stuff after the comma, and notice the starting brace) and hence not finding a match with the expected types.
To "solve" it in a dirty way, I added the following line (notice the "{" before "application/json")
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"{application/json"];
But we all know its not the right way. I don't know what is wrong here, is the server sending something incorrect? Or is RestKit supposed to read it differently?
Upvotes: 4
Views: 3496
Reputation: 1006
I couldn't find the reason why the server was returning a "Wrong" content type. The developers of the server denied that it was doing something wrong. So I ended up using my dirty hack and added a "{" before "application/json".
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"{application/json"];
Upvotes: 3