Tại sao tôi nhận được một HttpStatusCode là 0 nếu tôi chỉ dịch vụ mà khách hàng của tôi đang kết nối đến một URL không hợp lệ.Bắt một HttpStatusCode của 0
Trạng thái của tôiCodeAsInt hiển thị dưới dạng 0. Tại sao nó không hiển thị dưới dạng 404 và đang được xử lý?
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);
}
Cách thích hợp để xử lý RestResponse này là gì?
Cũng quan trọng cần lưu ý rằng lỗi 404 sẽ chỉ xảy ra nếu yêu cầu truy cập máy chủ web hợp lệ. Máy chủ web tạo mã trạng thái "404". – BinaryEvolved
Cảm ơn bạn, điều này rất hữu ích. – obizues