I'm trying to call a rest web service in an iOS application using Restkit but I get this error : restkit.network:RKObjectRequestOperation.m:210 response.body=415 Unsupported Media Type
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
and this is my request shown in the console
request.headers={
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]
method:RKRequestMethodPOST
pathPattern:nil
keyPath:@"OutputParameters"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];