【问题标题】:RestSharp - How do I get the numerical http response code?RestSharp - 如何获得数字 http 响应代码?
【发布时间】:2020-07-21 01:28:15
【问题描述】:

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

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

【问题讨论】:

    标签: c# http restsharp


    【解决方案1】:

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

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

    【讨论】:

    • 太棒了。我没有意识到 IRestResponse.StatusCode(或 RestResponse.StatusCode)是 HttpStatusCode 类型的。
    【解决方案2】:
    Assert.Equal(200, (int)response.StatusCode);
    

    【讨论】:

      猜你喜欢
      • 2013-05-23
      • 2015-10-15
      • 2015-03-07
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      相关资源
      最近更新 更多