Restkit response in text / xml

I have a WS that returns a plist.
I am using Restkit and I would like to display the answer.

So first, I initialize my ObjectManager as follows:

sharedInstance.manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]]; 

I accept text / xml:

 [[RKObjectManager sharedManager] setAcceptHeaderWithMIMEType:RKMIMETypeTextXML]; 

And I run my query:

 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?

+4
source share
3 answers

RestKit 0.20.0rc1 does not contain an XML serializer in the main repository, but you can find it here: RKXMLReaderSerialization .

Install via cocoapods: (or add source files to the project)

 pod 'RKXMLReaderSerialization', :git => 'https://github.com/RestKit/RKXMLReaderSerialization.git', :branch => 'master' 

Import the header in which you initialize RestKit.

 #import "RKXMLReaderSerialization.h" 

Finally, register the serialization class with RestKit. Paste this after initializing the object manager and before setting the accept header.

 sharedInstance.manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:ROOT_URL]]; [RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"application/xml"]; [[RKObjectManager sharedManager] setAcceptHeaderWithMIMEType:RKMIMETypeTextXML]; 
+10
source

Take a look at this link on the official RestKit gihub page. It is designed for 1.0

https://github.com/RestKit/RestKit/issues/1243

+2
source

1) You will need to tell RKObjectManager how to process the data that is serialized after the download process.

 [objectManager setRequestSerializationMIMEType:RKMIMETypeTextXML]; 

Edit:

I just saw that you are talking about a request, but using the method of sending an object to WS through POST.

To retrieve objects from the server, use the following method, which is described in the RestKit application examples.

 [[RKObjectManager sharedManager] getObjectsAtPath:@"yourPath" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { // Success } failure:^(RKObjectRequestOperation *operation, NSError *error) { // Error RKLogError(@"Load failed with error: %@", error); }]; 
0
source

All Articles