ios - Error with RestKit POST Request -
i trying send json data in post request server using restkit getting error
expected content type {( "application/x-www-form-urlencoded", "application/json" )}, got text/plain
the code have written is:
nsurl *url=[nsurl urlwithstring:[nsstring stringwithformat:@"%@%@",base_service_url,task_service_url]]; rkobjectmapping *mapping=[rkobjectmapping mappingforclass:[logindata class]]; [mapping addattributemappingsfromdictionary:@{@"s":@"status", @"message":@"message"}]; rkresponsedescriptor *descriptor=[rkresponsedescriptor responsedescriptorwithmapping:mapping method:rkrequestmethodpost pathpattern:nil keypath:@"" statuscodes:0]; nsmutableurlrequest *request=[[nsmutableurlrequest alloc]initwithurl:url]; [request sethttpmethod:@"post"]; [request addvalue:@"application/json" forhttpheaderfield:@"content-type"]; nsdictionary *dict=@{@"task":@"storeprofile", @"fdate":@"01.01.2013", @"tdate":@"19.08.2013", @"keyword":@"taxi && cab", @"alerthours":@"120", @"alertday":@"0", @"alerttimestart":@"12:00", @"alerttimeend":@"18:00", @"topic":@[ @{@"tname":@"politics"}, @{@"tname":@"economy"} ], @"publication":@[ @{@"pname":@"vijay times online"}, @{@"pname":@"leisure opportunities"} ] }; nserror *error=nil; nsdata *jsondata=[nsjsonserialization datawithjsonobject:dict options:kniloptions error:&error]; if (error) { nslog(@"%@",error.localizeddescription); return; } [request sethttpbody:jsondata]; operation=[[rkobjectrequestoperation alloc]initwithrequest:request responsedescriptors:@[descriptor]]; [operation setcompletionblockwithsuccess:^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult) { logindata *data=[mappingresult.dictionary objectforkey:@""]; nslog(@"%@",data.message); } failure:^(rkobjectrequestoperation *operation, nserror *error) { nslog(@"error:%@",error.localizeddescription); }]; [operation start];
could please me figure out problem is?? have tried setting content type follow also:
[request addvalue:@"application/application/x-www-form-urlencoded; charset=utf-8" forhttpheaderfield:@"content-type"];
you have register class rknsjsonserialization . please include below code in method.
[rkmimetypeserialization registerclass:[rknsjsonserialization class] formimetype:@"text/plain"];
Comments
Post a Comment