I have the following code:
NSURL *URL = [NSURL URLWithString:[@"some-address"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
RKObjectRequestOperation *requestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:[self.objectManager responseDescriptors]];
[requestOperation start];
[requestOperation waitUntilFinished];
I get the following error.
Object request failed: Underlying HTTP request operation failed with error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/plain" UserInfo=0x1f5e3c40 {NSLocalizedRecoverySuggestion={"total_rows":16,"offset":1,"rows":[
{"id":"1","key":1,"value":{"_id":"1","_rev":"1-e75042683867a7030fc4d3aa3b72ef35",
"user":{
"userId":"1",
"name":"A",
.......
]}}, .....
Why I get this error, when the response is in Json format?
The Javascript Object Notation(JSON) is used to transfer or exchange information on the internet. JSON is just the plain text written as a javascript object.
Valid Data Typesa string. a number. an object (JSON object) an array.
JSON stands for JavaScript Object Notation. JSON is a lightweight format for storing and transporting data. JSON is often used when data is sent from a server to a web page.
Send JSON Data from the Client SideUse JSON. stringify() to convert the JavaScript object into a JSON string. Send the URL-encoded JSON string to the server as part of the HTTP Request. This can be done using the HEAD, GET, or POST method by assigning the JSON string to a variable.
we did it. just set
[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"text/plain"];
and feel free to change RKXMLReaderSerialization class with RKNSJSONSerialization class if you're using JSON instead of XML (XML was our case).
You didn't set the mime-type header properly in your response. Note the error says got text/plain
, while the code is expecting either application/json
or application/x-www-form-urlencoded
.
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