Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the status description of NSHTTPURLResponse

I'm consuming a webservice and when something fails for validation reasons the error message is in the StatusDescription. I need a way to get that and display it to the user but all I see on NSHTTPURLResponse is the StatusCode and a way to convert the status code to the standard error message.

The web server always returns a 500 status code no matter the data error so I can't infer the problem from the code.

like image 675
Scotch Avatar asked Nov 14 '11 18:11

Scotch


1 Answers

You can obtain a standard error message like that:

[NSHTTPURLResponse localizedStringForStatusCode:httpResponse.statusCode];

Although there is no way to get the reason message from the given response using Foundation Framework if your server provides additional message there. You should use Core Foundation classes for that. The last provides such ability:

CFStringRef myStatusLine = CFHTTPMessageCopyResponseStatusLine(myResponse);

like image 122
Alexander Volkov Avatar answered Oct 11 '22 18:10

Alexander Volkov