Mane_87 Mane_87 - 3 months ago 32
iOS Question

415 Unsupported Media Type in Restkit response

I'm trying to call a rest web service in an iOS application using Restkit but I get this error : response.body=415 Unsupported Media Type

415 Unsupported Media Type

I puted this line in my code to set the content type as application/json:

objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

and this is my request shown in the console

Accept = "application/json";
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
Authorization = "Basic U1lTQURNSU46aHVsNTU4ODg1OA==";
"Content-Type" = "application/json; charset=utf-8";
"User-Agent" = "iosProj/1 (iPad Simulator; iOS 8.3; Scale/2.00)";

Then I found that the problem could be caused by "charset=utf-8" as mentioned here.
My question is how to remove "charset=utf-8" in Restkit


Thanks to @Wain comment I solved the problem by creating the request and setting the content type header :

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];    
[request setHTTPBody:jsonData];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor
                                            responseDescriptorWithMapping: [LoginResponse getResponseMapping]
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];