我使用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状态代码? 有更好的下载流的方法吗?
答案 0 :(得分:4)
执行请求后,您可以检查response.StatusCode和response.StatusDescription。
有趣的是,如果您使用此处所述的DownloadData方法https://github.com/restsharp/RestSharp/wiki/Other-Usage-Examples,就我所知,无法访问此信息。
答案 1 :(得分:0)
目前您可以使用属性 AdvancedResponseWriter 代替 ResponseWriter。
主要区别是AdvancedResponseWriter除了Response Stream之外,还得到了IHttpResponse,可以查看Response Status。
它应该从 106.6 版本开始正常工作。 https://github.com/restsharp/RestSharp/issues/1207