kmithi1
kmithi1

Reputation: 1758

AFNetworking returning response in NSError object

I was using NSURLConnection to consume service now I am switching to AFNetworking but getting some strange error. My code Note: CTPHTTPClient is subclass of AFHTTPClient

NSDictionary *parameters =  @{
                              @"email" : @"[email protected]",
                              @"confirmPassword" : @"12345",
                              @"userName" : @"mithilesh",
                              @"password" : @"12345",
                              @"termsAndConditionAccepted" : @1,
                              @"dob" : @"1190-03-05"
                              };

[[CTPHTTPClient sharedCTPHTTPClient] postPath:@"signup.json"
                                   parameters:parameters
                                      success: ^(AFHTTPRequestOperation *operation, id JSON){


                                          NSLog(@"Res = %@",JSON);

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

                                          [CTPUtilities showAlert:[error localizedDescription] delegate:self];
                                      }];

Response

enter image description here

In above response you can see the red rectangle Its contain the valid response. I am getting it correctly when using NSURLConnection.

Upvotes: 0

Views: 589

Answers (1)

Stepan Hruda
Stepan Hruda

Reputation: 596

The problem is probably the server side sending a failure HTTP status code. Although you are sending the correct payload, you should be basing the status of your request on the status code, not on the payload's content. AFNetworking does this for you, and as the AFNetworking error says, the server returned 500.

Upvotes: 3

Related Questions