【问题标题】:Download Stream with RestSharp and ResponseWriter使用 RestSharp 和 ResponseWriter 下载流
【发布时间】:2014-10-09 07:55:44
【问题描述】:

我使用 ResponseWriter 下载带有 RestSharp 的流。

var client = new RestClient
var request = new RestRequest();
// ...
request.ResponseWriter = (ms) => {
  // how to detect the status code
};
var response = client.Execute(request);

如何在 ResponseWriter 中找到 HTTP 状态码? 有没有更好的方法来下载 Stream?

【问题讨论】:

标签: http stream http-status-codes restsharp


【解决方案1】:

执行请求后可以查看response.StatusCode和response.StatusDescription。

有趣的是,如果您使用此处描述的 DownloadData 方法https://github.com/restsharp/RestSharp/wiki/Other-Usage-Examples,据我所知,无法访问此信息。

【讨论】:

  • 给定的链接没有产生预期的示例
【解决方案2】:

目前您可以使用属性 AdvancedResponseWriter 代替 ResponseWriter。

主要区别是AdvancedResponseWriter除了Response Stream之外还获取IHttpResponse,你可以查看Response Status。

它应该从 106.6 版本开始正常工作。 https://github.com/restsharp/RestSharp/issues/1207

【讨论】:

    猜你喜欢
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    相关资源
    最近更新 更多