I have a WS that return a plist.
I am using Restkit and I would like to map the response.
So first I initilialize my ObjectManager like this:
sharedInstance.manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]];
I accept the text/xml:
[[RKObjectManager sharedManager] setAcceptHeaderWithMIMEType:RKMIMETypeTextXML];
And I launch my request:
NSMutableURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:nil method:RKRequestMethodPOST path:@"/foo/foo" parameters:nil];
RKManagedObjectRequestOperation *operation = [[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:request managedObjectContext:[BddManager sharedInstance].manager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"Loading mapping result: %d", result.count);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Fail!");
}];
[operation start];
Finally I get this error:
NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/xml,
What am I doing wrong?
RestKit 0.20.0rc1 does not include an XML serializer in the main repository, but you can find one here: RKXMLReaderSerialization.
Install via cocoapods: (or add the source files to your project)
pod 'RKXMLReaderSerialization', :git => 'https://github.com/RestKit/RKXMLReaderSerialization.git', :branch => 'master'
Import the header where you initialize RestKit.
#import "RKXMLReaderSerialization.h"
Finally, register the serialization class with RestKit. Insert this after you initialize the object manager and before you set the accept header.
sharedInstance.manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]];
[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"application/xml"];
[[RKObjectManager sharedManager] setAcceptHeaderWithMIMEType:RKMIMETypeTextXML];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With