如果我将客户端连接的服务指向错误的URL,为什么会得到HttpStatusCode 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?