如果我指向我的客户端连接到一个错误的HttpStatusCode的服务,为什么我会得到一个0的URL。
我的statusCodeAsInt显示为0。为什么它不显示为404和正在处理?
代码语言:javascript复制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的正确方法是什么?