Search code examples
iosrestkitcontent-type

iOS - Content type error with RestKit


executing a GET request as follows:

manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:kBaseUrl]];
[manager setAcceptHeaderWithMIMEType:@"application/json"];
[manager setRequestSerializationMIMEType:RKMIMETypeJSON];

RKObjectRequestOperation* operation = [manager appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:@"www.mypath.com" parameters:nil];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    ....    
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    ....
}];
[manager enqueueObjectRequestOperation:operation];

even if the content type is set as 'application/json' I get:

Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {( "application/x-www-form-urlencoded", "text/html", "application/json" )}, got application/javascript"

Any idea?


Solution

  • It seems that no matter what the request content type is, the server's answer has always content type 'application/javascript'.

    The solution is:

    [RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"application/javascript"];