A status code of 0 in an NSHTTPURLResponse
object generally means there was no response, and can occur for various reasons. The server will never return a status of 0 as this is not a valid HTTP status code.
In your case, you are appearing to get a status code of 0 because the request is timing out and 0 is just the default value for the property. The timeout itself could be for various reasons, such as the server simply not responding in time, being blocked by a firewall, or your entire network connection being down. Usually in the case of the latter though the phone is smart enough to know it doesn't have a network connection and will fail immediately. However, it will still fail with an apparent status code of 0.
Note that in cases where the status code is 0, the real error is captured in the returned NSError
object, not the NSHTTPURLResponse
.
HTTP status 408
is pretty uncommon in my experience. I've never encountered one myself. But it is apparently used in cases where the client needs to maintain an active socket connection to the server, and the server is waiting on the client to send more data over the open socket, but it doesn't in a given amount of time and the server ends the connection with a 408
status code, essentially telling the client "you took too long".