Restkit failed to match response descriptors - ios

This is my JSON: link
This is my Mapper:
-(RKObjectManager *)mapContact{
RKObjectMapping* dataMapping = [RKObjectMapping mappingForClass:[Data class]];
[dataMapping addAttributeMappingsFromDictionary:#{
#"Data": #"app_data",
#"message": #"app_message",
#"status":#"app_status",
#"Success": #"app_success"
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dataMapping method:RKRequestMethodGET pathPattern:nil keyPath:#"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKEntityMapping* contactMapping = [RKEntityMapping mappingForEntityForName:#"Contact" inManagedObjectStore:managedObjectStore];
contactMapping.identificationAttributes = #[#"con_id"];
[contactMapping addAttributeMappingsFromDictionary:#{
#"content": #"con_content",
#"id" : #"con_id",
#"title" : #"con_title",
#"language":#"con_language",
}];
RKResponseDescriptor *responseDescriptor2 = [RKResponseDescriptor responseDescriptorWithMapping:contactMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:#"data.contentblock"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSArray *arrResponsDescriptor = [[NSArray alloc]initWithObjects:responseDescriptor,responseDescriptor2,nil];
[objectManager addResponseDescriptorsFromArray:arrResponsDescriptor];
return objectManager;
}
And this is my webservice call:
-(void)fetchContactOnCompletion:(myCompletion) compblock{
Mapper *mapper = [Mapper new];
RKManagedObjectStore *store = [[ASLDataModel sharedDataModel] objectStore];
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
RKObjectManager *objectManager = [mapper mapContact];
NSString *urlString = [NSString stringWithFormat:#"webservice/content/get/apikey/%#/language/%#/contentid/2",apikey,language];
NSURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:urlString parameters:nil];
RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
Data *data = [mappingResult.dictionary valueForKey:#""];
if([data.app_status isEqualToNumber:#200]){
NSError *error = nil;
BOOL success = [context save:&error];
if (!success) RKLogWarning(#"Failed saving managed object context: %#", error);
NSError *saveError = nil;
compblock(YES);
}else{
compblock(NO);
}
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
[objectManager enqueueObjectRequestOperation:operation];
}
And I get these errors:
2015-09-08 08:38:56.431 ASLTravel[17377:427756] D restkit.object_mapping:RKMapperOperation.m:433 Finished performing object mapping. Results: (null)
2015-09-08 08:38:56.432 ASLTravel[17377:427753] E restkit.network:RKObjectRequestOperation.m:209 GET 'http://asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2' (200 OK / 0 objects) [request=1.6674s mapping=0.0000s total=1.6899s]:
error=Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x7f9413f8b730 {NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2', which failed to match all (2) response descriptors:
<RKResponseDescriptor: 0x7f9413f535e0 baseURL=http://asl-travel.be/ pathPattern=(null) statusCodes=200-299> failed to match: response URL 'http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2' is not relative to the baseURL 'http://asl-travel.be/'.
<RKResponseDescriptor: 0x7f9413f2b1e0 baseURL=http://asl-travel.be/ pathPattern=(null) statusCodes=200-299> failed to match: response URL 'http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2' is not relative to the baseURL 'http://asl-travel.be/'., NSErrorFailingURLStringKey=http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2, NSErrorFailingURLKey=http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2, NSUnderlyingError=0x7f9413c2fc20 "No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.}
Can anyone please help me with this? I'm searching for this problem for hours now...
Many thanks !

The web service is redirecting you to www.asl-travel.be so the pattern matcher will never find a match. Update the base URL or turn off the redirection to fix this.

Related

Setting up iOS Restkit with Django Rest Framework

I have an API sitting at this url: https://evening-everglades-1560.herokuapp.com/api/v1/stocks/
I am trying to implement iOS RestKit with like so (this is in MasterViewController.m):
RKObjectMapping *stockMapping = [RKObjectMapping mappingForClass:[Stock class]];
[stockMapping addAttributeMappingsFromDictionary:#{#"stockId": #"id"}];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:stockMapping method:RKRequestMethodAny pathPattern:nil keyPath:#"" statusCodes:statusCodes];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"https://evening-everglades-1560.herokuapp.com/api/v1/stocks.json"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:#[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
Stock *stock = [result firstObject];
NSLog(#"mapped w stock: %#", stock);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"failed w error: %#", [error localizedDescription]);
}];
[operation start];
This is what is logged:
2016-01-17 16:42:08.233 Stocks[9415:1208281] W restkit.object_mapping:RKMapperOperation.m:99 Adding mapping error: No mappable values found for any of the attributes or relationship mappings
2016-01-17 16:42:08.234 Stocks[9415:1208308] I restkit.network:RKObjectRequestOperation.m:250 GET 'https://evening-everglades-1560.herokuapp.com/api/v1/stocks.json' (200 OK / 0 objects) [request=0.4798s mapping=0.0042s total=0.5528s]
2016-01-17 16:42:08.235 Stocks[9415:1208245] mapped w stock: (null)`
I am not sure of what to put for the pathPattern and keyPath.
Thanks in advance!
It is fixed thanks to wain inquiring about "you haven't given your object definition." I forgot to define submitter in my stock.h cocoa class.
Adding #property(nonatomic, strong) NSString *submitter; to stock.h fixed it.

RestKit Put service is not affecting database data on server even getting response is success

I am developing iPhone application and using Restkit for consuming services and put data on server. I am working with Restkit first time. I want to put data on server then I implemented the restkit put method, and it executed successfully and getting response "SUCCESS" but when I retrieving data then it doesn't affecting data means not getting last put data on server. So can anybody tell me what is wrong with this?? I used the following code I used :
////Response Mapping values
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[NSMutableArray class]];
[responseMapping addAttributeMappingsFromArray:#[#"SenderId", #"SentDate", #"Status",#"GroupId", #"Message"]];
//Request Mapping values
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; // objectClass == NSMutableDictionary
[requestMapping addAttributeMappingsFromArray:#[#"SenderId", #"SentDate", #"Status",#"GroupId", #"Message"]];
ITRestKitServices *restkitService = [[ITRestKitServices alloc] initWithDelegate:self];
[restkitService putDataONserverBulletin:bulletinMutableArray pathPattern:#"bulletin" keyPath:#"" userName:appDelegate.user.Email password:appDelegate.user.SessionToken requestMapping:requestMapping responseMapping:responseMapping];
// And following code to put data on server in service I used:
// initialize AFNetworking HTTPClient
NSURL *baseURL = [NSURL URLWithString:BASE_URL_STRING];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[client setAuthorizationHeaderWithUsername:userName password:password];
//set pathPattern
NSString *path = [NSString stringWithFormat:#"%#/%#",BASE_PATH_STRING,pathPattern];
//StatusCodes
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
//Request Descriptor
RKRequestDescriptor *requestDescriptor =
[RKRequestDescriptor requestDescriptorWithMapping:requestMapping
objectClass:[Bulletin class]
rootKeyPath:nil
method:RKRequestMethodPUT];
//Response Descriptor
RKResponseDescriptor *userResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:responseMapping
method:RKRequestMethodPUT
pathPattern:path
keyPath:keyPath
statusCodes:statusCodes];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
[objectManager addRequestDescriptor:requestDescriptor];
[objectManager addResponseDescriptor:userResponseDescriptor];
AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
if(appDelegate.isLoading == NO)
{
[appDelegate startLoading];
}
[objectManager putObject:dataObject
path:path
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
NSLog(#"Bulletin Success");
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
if(appDelegate.isLoading == YES)
{
[appDelegate stopLoading];
}
NSLog(#">>> Error: %#", error);
}];

RestKitObjectMapping Array off null objects

RestKitObjectMapping Array off null objects
I want to map CapitalImage object in Capital images object property.
//------------------------ The mapping I try to
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class]
forMIMEType:#"text/html"];
RKObjectMapping *CapitalImageMap = [RKObjectMapping mappingForClass:[CapitalImage class]];
[CapitalImageMap addAttributeMappingsFromDictionary:#{
#"src": #"src"
}];
RKObjectMapping *CapitalMap = [RKObjectMapping mappingForClass:[Capital class]];
[CapitalMap addAttributeMappingsFromDictionary:#{
#"name": #"name",
#"text": #"text"
}];
[CapitalMap addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"images" toKeyPath:#"images" withMapping:CapitalImageMap]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:CapitalMap
method:RKRequestMethodAny
pathPattern:nil
keyPath:nil
statusCodes:statusCodes];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.a10073.de4.dp10.ru/icapitals/capital.php"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:#[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
Capital *article = [result firstObject];
NSLog(#"Mapped the article: %# , %#", article.name,article.images.description);
} failure:^(RKObjectRequestOperation *operation, NSError *error) { NSLog(#"Failed with error: %#", [error localizedDescription]); }];
[operation start];
I get this result
2013-09-27 23:20:49.028 iCapitals v2[5099:c07] Mapped the article: London , (
(null),
(null),
(null),
)
LOGS - http://www.a10073.de4.dp10.ru/icapitals/consoleresult.txt
Please check the code and tell what i do wrong, Thanks!!!
Your mappings look correct. The log shows the mapping proceeding correctly. The issue appears to be with the CapitalImage class. Why is it giving a nil description? It could be that that is the only problem. So your log of the array is a list of nil, but the objects do exist.
Try logging the src of each objects. Are you seeing other issues? Did you implement the description method?

iOS RestKit issue: Invalid parameter not satisfying: responseDescriptors

I am trying to use RestKit to retrieve a listing of events and I keep getting this:
2013-05-20 10:52:56.708 EventApp[3380:c07] I restkit:RKLog.m:34 RestKit logging initialized...
2013-05-20 10:52:56.773 EventApp[3380:c07] *** Assertion failure in -[RKObjectRequestOperation initWithRequest:responseDescriptors:], /Users/mitchell/Desktop/eventapp/take2/EventApp/Pods/RestKit/Code/Network/RKObjectRequestOperation.m:158
2013-05-20 10:52:56.774 EventApp[3380:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: responseDescriptors'
I have been scratching my head for days on this one. As I have a fair amount of gaps in my iOS dev skills(about one project every year) it would greatly help if someone can just lead me in the right direction here using some laymen terms.
Please consider that I am looking to use enqueueObjectRequestOperation specifically for batching multiple requests. I have just pieced together bits of my code for translation here.
Here is what my datamodel looks like:
Here is the what the JSON file looks like:
[{
"id":1,
"farm_id":1,
"all_day": "NO",
"from": "2013-05-08T18:45:38Z",
"to": "2013-05-08T18:45:38Z",
"name": "event 1",
"desc": "some description",
"photo": "some.png",
"price": "price"
}]
Here is my code:
NSManagedObjectContext *context;
RKObjectManager *objectManager;
if (self.eventContext == nil) {
NSError *error = nil;
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"FarmApp" ofType:#"momd"]];
RKEntityMapping *entityMapping;
// NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
// Initialize the Core Data stack
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore __unused *eventPersistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
NSAssert(eventPersistentStore, #"Failed to add persistent store: %#", error);
[managedObjectStore createManagedObjectContexts];
// Set the default store shared instance
[RKManagedObjectStore setDefaultStore:managedObjectStore];
// Configure the object manager
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:#"http://sandbox.bm.com"]];
[RKObjectManager setSharedManager:objectManager];
[objectManager setRequestSerializationMIMEType:#"application/json"];
[objectManager setAcceptHeaderWithMIMEType:#"text/plain"];
objectManager.managedObjectStore = managedObjectStore;
entityMapping = [RKEntityMapping mappingForEntityForName:#"Event" inManagedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:#{
#"id": #"eventID",
#"farm_id": #"farm",
#"all_day": #"allDay",
#"from": #"from",
#"to": #"to",
#"name": #"name",
#"desc": #"desc",
#"photo": #"photo",
#"price": #"price"
}];
RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:successDescriptor];
RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:#"errors" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];
[objectManager addResponseDescriptor:errorDescriptor];
self.eventContext = managedObjectStore.mainQueueManagedObjectContext;
}
context = self.eventContext;
NSString* url = [NSString stringWithFormat:#"http://sandbox.bm.com/farmapp/%#.json", #"events"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:[objectManager responseDescriptors]];
[operation setCompletionBlockWithSuccess:nil failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Loaded this error: %#", [error localizedDescription]);
}];
NSArray *operations = [NSArray arrayWithObjects:operation, nil];
for (int i = 0; i < [operations count]; i++ ) {
[[RKObjectManager sharedManager] enqueueObjectRequestOperation:[operations objectAtIndex:i]];
}
Can someone out there help me?
Here is the final solution
if (self.eventContext == nil) {
NSManagedObjectContext *context;
RKObjectManager *objectManager;
NSError *error = nil;
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"FarmApp" ofType:#"momd"]];
RKEntityMapping *entityMapping;
// NOTE: Due to an iOS 5 bug, the managed object model returned is immutable.
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
// Initialize the Core Data stack
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore __unused *eventPersistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
NSAssert(eventPersistentStore, #"Failed to add persistent store: %#", error);
[managedObjectStore createManagedObjectContexts];
// Set the default store shared instance
[RKManagedObjectStore setDefaultStore:managedObjectStore];
// Configure the object manager
objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:#"http://sandbox.bm.com"]];
[RKObjectManager setSharedManager:objectManager];
[objectManager setRequestSerializationMIMEType:#"application/json"];
[objectManager setAcceptHeaderWithMIMEType:#"text/plain"];
objectManager.managedObjectStore = managedObjectStore;
entityMapping = [RKEntityMapping mappingForEntityForName:#"Event" inManagedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:#{
#"id": #"eventID",
//#"farm_id": #"farm",-->cannot create relationship this way
#"farm_id" : #"farmID",//farmID attribute needs to be added to Event's model
#"all_day": #"allDay",
#"from": #"from",
#"to": #"to",
#"name": #"name",
#"desc": #"desc",
#"photo": #"photo",
#"price": #"price"
}];
[entityMapping addConnectionForRelationship:#"farm" connectedBy:#"farmID"];
RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:#"events" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:successDescriptor];
RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:#"errors" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];
[objectManager addResponseDescriptor:errorDescriptor];
self.eventContext = managedObjectStore.mainQueueManagedObjectContext;
context = self.eventContext;
NSString* url = [NSString stringWithFormat:#"http://sandbox.bm.com/farmapp/%#.json", #"events"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"Success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Failure");
}];
NSArray *operations = [NSArray arrayWithObjects:operation, nil];
for (int i = 0; i < [operations count]; i++ ) {
[[RKObjectManager sharedManager] enqueueObjectRequestOperation:[operations objectAtIndex:i]];
}
}
As #JoelH. suggests in one of his comments, you need to use RKManagedObjectRequestOperation instead of RKObjectRequestOperation.
For example :
RKManagedObjectRequestOperation *operation = [objectmanager managedObjectRequestOperationWithRequest:request managedObjectContext:managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"Success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"Failure");
}];
Besides, I think the way you are mapping
#"farm_id": #"farm"
is not correct.
If you want to build the relationship between Event and Farm, you need to use one of these methods :
relationshipMappingFromKeyPath:toKeyPath:withMapping:
or addConnectionForRelationship:connectedBy:
If the Farm object already exists and you only want to map the new Event, I would go for addConnectionForRelationship:connectedBy:
For example :
RKEntityMapping* eventMapping = [RKEntityMapping mappingForEntityForName:#"Event" inManagedObjectStore:managedObjectStore];
[entityMapping addAttributeMappingsFromDictionary:#{
#"id": #"eventID",
//#"farm_id": #"farm",-->cannot create relationship this way
#"farm_id" : #"farmID",//farmID attribute needs to be added to Event's model
#"all_day": #"allDay",
#"from": #"from",
#"to": #"to",
#"name": #"name",
#"desc": #"desc",
#"photo": #"photo",
#"price": #"price"
}];
[eventMapping addConnectionForRelationship:#"farm" connectedBy:#"farmID"];
It would also require to add a farmID attribute in your Event model, as RestKit does not allow relationship connection without intermediary attributes yet.
The RestKit docs (Mapping Without KVC) seem to imply that if you don't have a KVC label on the top level(e.g. events:[]), a pathPattern: is required for the parser to know which mapping to use. Since both your keyPath: and pathPattern: are nil for your successDescriptor, I have two suggestions:
If changing the JSON structure is possible, change the top level to { events:[...] } and change keyPath:nil to keyPath:#"events" to reflect this change.
If it's not possible, change pathPattern:nil to pathPattern:#"/farmapp" Notice, I set pathPattern: to match your resource URL. This second suggestion might not work if you have other types of resources branching from that URL as well.
Also, I noticed that your errorDescriptor uses the same mapping(entityMapping) as your successDescriptor. I don't know if that's what you intended, but if your error response is supposed to be some different error object, I suggest changing that.
Hope this helps!

RestKit 0.20 Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016

I am trying to integrate RestKit 0.20 to My Project So for Example i am using google rss reader for sample project.
This is the response for Xml
/
/category>
&
This is the Xml from where i have to get the data.
RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[News class]];
[articleMapping addAttributeMappingsFromDictionary:#{
#"title": #"title",
#"link": #"link",
#"guid": #"guid",
#"pubDate": #"pubDate",
#"description": #"description"
}];
NSURL* url = [[NSURL alloc]initWithString:#"http://news.google.com"];
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:url];
NSURLRequest* request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:#"/?output=rss" parameters:nil];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:articleMapping pathPattern:nil keyPath:#"item" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:#[ responseDescriptor ]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(#"Load collection of Articles: %#", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(#"Operation failed with error: %#", error);
}];
[objectRequestOperation start];
Above is the code i used to get data When i run the app i am getting the following error
I restkit.network:RKObjectRequestOperation.m:174 GET 'http://news.google.com/?output=rss'
2013-05-28 12:24:15.076 TestApp[8940:15203] E restkit.network:RKObjectRequestOperation.m:569 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
"application/xml",
"application/x-www-form-urlencoded",
"application/json"
)}, got application/rss+xml" UserInfo=0xa80a3d0 {NSLocalizedRecoverySuggestion=NFE/1.0Top Stories - Google News
Can any one help
As the exception says, RestKit is expecting one of:
"application/xml"
"application/x-www-form-urlencoded"
"application/json"
But it's receiving "application/rss+xml". You just need to tell RestKit what to expect.
You can ask RestKit if it already understands the mime type:
[RKMIMETypeSerialization registeredMIMETypes];
If not you'll need to register a serializer with RKMIMETypeSerialization.
And you can tell the object manager what mime type to expect:
[objectManager setAcceptHeaderWithMIMEType:#"application/rss+xml"];

Resources