1

I am using AFNetworking to get the data from server using post methods in iOS but i am getting status code 200 OK but in AFNetworking its comes in Failure methods and its display below error I have also search on google and i have tried based on result also but its display same error.

Waiting for your reply.

Status code :-

{ status code: 200, headers {
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/html"

Error :- Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7f838a5df950 {NSDebugDescription=Invalid value around character 0.}

Here is my code :-

NSError *error;
NSDictionary *result;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictPost
                options:kNilOptions    error:&error];
if (! jsonData) {
} else {

    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    result = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

}

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[manager setResponseSerializer:responseSerializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];*


[manager POST:@“http:www.server.url.com” parameters:result success:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSLog(@"JSON: %@", responseObject);


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@“Error: %@", error.description);

}];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rushabh
  • 3,208
  • 5
  • 28
  • 51
  • Could you please reformat the code? – Bojan Dimovski May 03 '15 at 20:09
  • Did you ever resolve this problem? I have the same problem and all the solutions I have tried on this linke and a few others haven't worked --http://stackoverflow.com/questions/19114623/request-failed-unacceptable-content-type-text-html-using-afnetworking-2-0 – Allen Apr 21 '16 at 20:37
  • @Allen I have resolved above issue . – Rushabh Apr 22 '16 at 06:45

1 Answers1

0

I think your problem is related to this answer.

There is probably an error in the response itself, which cannot be parsed as a valid JSON.

I'd try to debug the server response using a 3rd party tool, such as Postman for Chrome.

Updated: Your content type should be application/json.

Community
  • 1
  • 1
Bojan Dimovski
  • 1,216
  • 11
  • 25
  • thanks for reply but i had done changes based on your reference URL and i also check in Postman and Restclient when i send request using tool in form-data then i getting response success but when i send request using form-data from iOS programming then it give me the error.I am gettign success code 200 OK but i am not getting response we is getting in POSTMAN and RESTclient any idea ? – Rushabh May 04 '15 at 02:51