5
一个HttpStatusCode为什么我收到的0 HttpStatusCode如果我点我的客户端连接到一个坏的URL的服务。获取的0
我statusCodeAsInt被显示为0。为什么不显示为404和正在处理的?
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);
}
什么是正确的方式来处理这RestResponse?
另外需要注意的是,如果请求命中一个有效的Web服务器时,才会发生404错误。 Web服务器创建“404”状态码。 – BinaryEvolved
谢谢,这很有帮助。 – obizues