RestSharp -我如何得到数值http响应代码

本文关键字:http 响应 代码 何得 RestSharp | 更新日期: 2023-09-27 17:54:57

我正在使用c#的RestSharp HTTP客户端库。

如何检索实际的数字http响应代码?我不仅没有看到包含数字代码的属性,而且我甚至没有在header集合中看到它

RestSharp -我如何得到数值http响应代码

只需从RestResponse对象中获取StatusCode属性并将枚举值强制转换为int。

RestResponse response = client.Execute(request);
HttpStatusCode statusCode = response.StatusCode;
int numericStatusCode = (int)statusCode;
Assert.Equal(200, (int)response.StatusCode);