0
votes

I am trying to make a POST request using AFNetworking 2.0. This is the code

NSMutableDictionary *params=[NSMutableDictionary dictionary];
[params setValue:@"iOS" forKey:@"device"];
[params setValue:@"" forKey:@"token"];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];

[manager POST:ServerURL parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",responseObject);

}

failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@",error);
}];

I have followed many question and they all have done something similar to what i have done above . I do not understand what i am missing. i get a valid response using the old Afnetworking library.

The error i get is

{ status code: 200, headers { Connection = close; "Content-Length" = 195; "Content-Type" = "text/html; charset=UTF-8"; Date = "Mon, 21 Apr 2014 06:53:55 GMT"; Server = "Apache/2.2.25 (Amazon)"; "X-Powered-By" = "PHP/5.3.27"; } }, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

1
This is not error. 200 means all is well. try to log operation.responseObject or operation.responseData. - CRDave
Yes i understand. But then y is the failure block called? The above response is the error NSlog - Nitesh

1 Answers

0
votes

I resolved it by adding

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

not sure if this is the right way , but it worked for me

Cheers.