Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download Stream with RestSharp and ResponseWriter

I donwnload a stream with RestSharp by using the ResponseWriter.

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

How can I found out the HTTP Status Code in the ResponseWriter? Is there a better way to download a Stream?

like image 631
koalabruder Avatar asked Oct 09 '14 07:10

koalabruder


2 Answers

You can check response.StatusCode and response.StatusDescription after executing the request.

Interestingly, if you use the DownloadData method as described here https://github.com/restsharp/RestSharp/wiki/Other-Usage-Examples there is no way to access this information as far as I can tell.

like image 142
Oremac Avatar answered Oct 13 '22 10:10

Oremac


Currently You can use property AdvancedResponseWriter instead ResponseWriter.

The main difference is that AdvancedResponseWriter in addition to Response Stream gets IHttpResponse and You can check Response Status.

It should be working properly from version 106.6. https://github.com/restsharp/RestSharp/issues/1207

like image 42
ExplosiveMango Avatar answered Oct 13 '22 11:10

ExplosiveMango