1

I am using AFNetwoking, AFHTTPClient object to hit a REST API with verb PUT. What I get in response is: status 500 along with the custom status message in response header field s in status code field.

Response header field: Status Code: 500 Please check you van number and try again.

Basically the issue is to parse this status message. Here is the code:

NSHTTPURLResponse *response;
NSMutableURLRequest *request = [httpClient requestWithMethod:PUT_CALL path:requestUrl parameters:params];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

response object has no getter to get this status message. When I tried to get all response header fields, I get all the key value pairs except the status code field in which message is also coming.

pnuts
  • 58,317
  • 11
  • 87
  • 139
User
  • 11
  • 4
  • Why would the message be in the status code header? – Wain Oct 29 '13 at 13:08
  • I am not sure what is the standard way to put the message and code. But the server we are hitting is sending the message this way along with status code. But the interesting thing is we are also parsing it for android using HttpsURLConnection class object and this connection object provides a getter to get the status message. How can i get this for iOS? – User Oct 29 '13 at 13:12

1 Answers1

-1

You can get status code in delegate method -didRecieveResponse:

    - (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
       NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
       int code = [httpResponse statusCode];
    }

//Get the Body of the response
-   (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData{
    NSLog(@"String sent from server %@",[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding]);

}
Nikos M.
  • 13,685
  • 4
  • 47
  • 61