Search code examples
httpstreamhttp-status-codesrestsharp

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?


Solution

  • 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.