Search code examples
iphoneobjective-cnsurlconnectionhttp-status-codes

how do I check an http request response status code from iOS?


I am sending an http request from iOS (iPad/iPhone) to my python google app engine server using the NSURLConnection and NSURLRequest classes.

How do I read the response's status, i.e. the value set by app engine using response.set_status(200, message="Success") for instance?

I'm not able to find where I can read these status codes once I receive the NSURLConnection's connectionDidFinishLoading delegate call on the client end.


Solution

  • The connection:didReceiveResponse: delegate method is called when a response is received, which gives you an NSURLResponse to play with.

    If you've made an HTTP request, then it'll actually be an NSHTTPURLResponse object, which has a statusCode method.