我想知道是否有一种更简单(更好的)方法来检查500状态码?
我能想到的唯一方法是这样做:
var statusCodes = new List<HttpStatusCode>()
{
HttpStatusCode.BadGateway,
HttpStatusCode.GatewayTimeout,
HttpStatusCode.HttpVersionNotSupported,
HttpStatusCode.InternalServerError,
HttpStatusCode.NotImplemented,
HttpStatusCode.ServiceUnavailable
};
if (statusCodes.Contains(response.StatusCode))
{
throw new HttpRequestException("Blah");
}
我注意到这些是500种类型:
- BadGateway
- GatewayTimeout
- HttpVersionNotSupported
- InternalServerError
- NotImplemented
- ServiceUnavailable