我想知道是否有更简单的方法(更好的方法)来检查 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 种类型:
- 错误的网关
- 网关超时
- HttpVersionNotSupported
- 内部服务器错误
- 未实现
- 暂停服务