Download Stream with RestSharp and ResponseWriter

11,131

Solution 1

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.

Solution 2

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

Share:
11,131
koalabruder
Author by

koalabruder

Updated on July 30, 2022

Comments

  • koalabruder
    koalabruder over 1 year

    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?