Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a HttpStatusCode of 0

Why am I getting a HttpStatusCode of 0 if I point the service my client is connecting to to a bad URL.

My statusCodeAsInt is showing up as a 0. Why is it not showing up as a 404 and being handled?

IRestResponse response = client.Execute(restReq); HttpStatusCode statusCode = response.StatusCode;  var statusCodeAsInt = (int) statusCode;          if (statusCodeAsInt >= 500)         {             throw new InvalidOperationException("A server error occurred: " + response.ErrorMessage, response.ErrorException);         }         if (statusCodeAsInt >= 400)         {             throw new InvalidOperationException("Request could not be understood by the server: " + response.ErrorMessage,                 response.ErrorException);         } 

What is the proper way to handle this RestResponse?

like image 299
obizues Avatar asked Jan 14 '16 17:01

obizues


People also ask

What does a 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").

What does Ajax Error 0 mean?

Status code 0 means the requested url is not reachable.


1 Answers

In my case it was not a firewall issue causing the StatusCode of 0. We were using a legacy app that was still using TLS 1.0 on a server that had blocked TLS 1.0 connections. Once we enabled TLS 1.2, we got the status codes we were expecting.

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
like image 169
KJ3 Avatar answered Sep 18 '22 12:09

KJ3