I am working on an iOS project.
In this application, I am downloading images from the server.
Problem:
While downloading images I a
The Response was Empty. Most of the case the codes will stats with 1xx, 2xx, 3xx, 4xx, 5xx.
List of HTTP status codes
Sometimes Browser respond to http error handler with Error Object, that have status set to 0, even if you can see 404, 401, 500 etc. error status in network.
This could happen if your Application and API are on different domains - CORS mechanism is applied. According to CORS for each API request browser sends two requests:
In Application we are handling Error response for "Actual/Origin request", and if "preflight OPTIONS request" failed - browser doesn't give correct HttpError object for http error handler. So to get correct status of http response - be sure to get success preflight OPTIONS request response.
HTTP response 0 is not standard HTTP response. But it indicates that client could not connect with server and hence forth time out happened.
This can happen with a 401 http response if using NSURLConnection.
See NSURLConnection returning error instead of response for 401
On gate way timeout, status will be zero on your error call back.
.error( function( data,status,headers,config){
console.log(status)
}
HTTP status codes
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".