RestSharp - 如何获取数字http响应代码?

问题描述 投票:10回答:2

我正在为C#使用RestSharp HTTP客户端库。

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

c# http restsharp
2个回答
27
投票

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

RestResponse response = client.Execute(request);
HttpStatusCode statusCode = response.StatusCode;
int numericStatusCode = (int)statusCode;

-2
投票
Assert.Equal(200, (int)response.StatusCode);
© www.soinside.com 2019 - 2024. All rights reserved.