HTTP Status Code 0 - Domain Error = NSURLErrorDomain?

I am working on an iOS project.

In this application, I upload images from the server.

Problem:

When uploading images, I get a request timeout . According to the documentation, the HTTP request timeout status code is 408 .

But in my application, I get an HTTP status code 0 with the following error

Domain Error = NSURLErrorDomain Code = -1001 "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 NSextUrror = 0x13846870 "Timed out."}

While searching the internet, I did not find any information about the HTTP Status Code 0.

Can anyone explain this to me?

+77
download nserror
Nov 08 '13 at 11:40
source share
12 answers

There is no HTTP status code 0. What you see is 0 returned by the API / library that you are using. To do this, you will need to check the documentation.

+73
Nov 08 '13 at 15:23
source

The status code 0 in the NSHTTPURLResponse object usually means that there was no response, and can occur for various reasons. The server will never return status 0, as this is not a valid HTTP status code.

In your case, you get a status code of 0 because the request is a timeout, and 0 is only the default value for the property. The timeout by itself can be for various reasons, for example, the server simply does not respond on time, is blocked by a firewall, or the entire network connection is disconnected. Usually in the case of the latter, although the phone is smart enough to know that it does not have a network connection, it will work immediately. However, it will still work with an explicit status code of 0.

Note that in cases where the status code is 0, the real error is fixed in the returned NSError object, and not in NSHTTPURLResponse .

The status of HTTP 408 quite rare in my experience. I have never come across this myself. But, apparently, it is used in cases where the client needs to maintain an active connection from the socket to the server, and the server expects the client to send more data through the open socket, but this is not done at the specified time and the server ends the connection with the 408 status code. essentially telling the customer "you take too long."

+60
Apr 27 '15 at 23:08
source

In the iOS SDK. When your API calls timeouts, you get the status 0 for this.

+9
Oct 13 '14 at 10:48
source

The answer was empty. In most cases, codes will be recorded from 1xx, 2xx, 3xx, 4xx, 5xx.

List of HTTP Status Codes

+7
Nov 08 '13 at 11:45
source

From my limited experience, I would say that the following two scenarios can trigger a status code: 0 response status code: 0 , keep in mind; there may be more, but I know about these two:

  • your connection may respond slowly.
  • or perhaps the back-end server is unavailable.

the thing is that status: 0 somewhat generalized, and there may be more use cases that cause empty response bodies.

+5
Jun 17 '15 at 10:57
source

HTTP response 0 is not a standard HTTP response. But this indicates that the client could not connect to the server and, therefore, a timeout occurred

+3
Jun 27 '18 at 3:10
source

We received an error message:

GET http: //localhost/pathToWebSite/somePage.aspx raised the error http.status: 0

This call is made from a Windows task that calls the VBS file, therefore, to fix the problem, the browser is specified for the URL, and we receive a privacy message:

Your connection is not private

Attackers may try to steal your information from a local host (for example, passwords, messages or credit cards). NET :: ERR_CERT_COMMON_NAME_INVALID

Automatically report potential security incidents to Google. Privacy Policy Back to Security This server could not prove that it is local; its security certificate is from * .ourdomain.com. This could be due to a misconfiguration or an attacker intercepting your connection. More details

This is because we have a rule of rewriting the IIS URL to force connections to use https. This rule distracts http: // localhost to https: // localhost but our SSL certificate is based on an external domain name, not localhost, so the error that is reported as a status code is 0. Thus, the privacy error can be a very obscure reason for this. status code.

In our case, the solution was to add an exception to the rule for localhost and allow http: //localhost/pathToWebSite/somePage.aspx to use http. It is not clear, yes, but I will be faced with this next year, and now I will find my answer in a Google search.

+2
May 5 '17 at 23:55
source

CORS in my case.

I had this answer in an iOS app once. The solution was the lack of Access-Control-Allow-Origin: * in the headers.

More details: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

+1
Aug 14 '18 at 10:32
source

The status code "0" can occur for three reasons.
1) The client cannot connect to the server
2) The client cannot receive a response during the waiting period
3) The request was β€œstopped (canceled)” by the Client.

But these three reasons are not standardized.

+1
Sep 14 '18 at 8:03
source

I have java script ajax client and nodejs express server

Client code is as follows:

 ... var status1 = xmlHttpRequest.status; ... 

The server code is as follows:

 ... // An exception here results HTTP status codes in status1 (at client side above) ... ... var reqDb = http.request(options, requestCompleteCallback); ... ... function requestCompleteCallback(response) { ... // An exception here results in 0 in status1 (at client side above) ... } 

30 minutes of struggle to figure it out.
Hope this post helps someone.

Good luck.

0
Jul 23 '15 at 9:04
source

With a timeout in standby mode, the status will be zero when the callback is called.

 .error( function( data,status,headers,config){ console.log(status) } 

HTTP status codes

0
Mar 15 '17 at 10:51
source

Sometimes the browser responds to the http error handler using the Error object, whose state is set to 0, even if you see an error state of 404, 401, 500, etc. Online.

This can happen if your application and API are in different domains - the CORS mechanism is applied. According to CORS, for each API request, the browser sends two requests:

  1. a preflight OPTIONS request to see if the API allows an Actual / Origin request.
  2. when the API allows (the OPTIOS request responds with a state of 204 and the correct Access-Control-Allow-Origin headers) - the browser sends the next "Actual / Origin request".

In the Appendix, we process the "Error" response for the "Actual / Original request", and if the "preflight OPTIONS request" fails, the browser does not throw the correct HttpError object for the http error handler. Thus, in order to get the correct status of the response http - be sure to get a preliminary response request OPTIONS.

0
Jan 18 '19 at 6:58
source



All Articles