Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP status code 0 - Error Domain=NSURLErrorDomain?

I am working on an iOS project.

In this application, I am downloading images from the server.

Problem:

While downloading images I am getting Request Timeout. According to documentation HTTP status code of request timeout is 408.

But in my application, I am getting HTTP status code 0 with the following error

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0xb9af710 {NSErrorFailingURLStringKey=http://xxxx.com/resources/p/PNG/1383906967_5621_63.jpg, NSErrorFailingURLKey=http://xxxx.com/resources/p/PNG/1383906967_5621_63.jpg, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x13846870 "The request timed out."}

During a search, over internet, I found no information about HTTP Status Code 0.

Can anyone explain this to me?

like image 469
Irfan DANISH Avatar asked Nov 08 '13 11:11

Irfan DANISH


People also ask

What does HTTP status code 0 mean?

HTTP StatusCode=0 is associated with incomplete capture of a hit or page and often with a labeling of the hit as: request canceled ("ReqCancelled=Client" "ReqCancelled=Server" or "ReqCancelled=True").

When response code is 0?

HTTP connection error: response code 0 is caused by an unreachable server. For example, a program that handles HTTP connections as a proxy is not running, but the client is configured to use this proxy.


2 Answers

There is no HTTP status code 0. What you see is a 0 returned by the API/library that you are using. You will have to check the documentation for that.

like image 90
Julian Reschke Avatar answered Oct 19 '22 04:10

Julian Reschke


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".

like image 92
devios1 Avatar answered Oct 19 '22 04:10

devios1