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