Download Stream with RestSharp and ResponseWriter
Asked Answered
M

2

6

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?

Manofwar answered 9/10, 2014 at 7:55 Comment(1)
github.com/restsharp/RestSharp/wiki/Getting-Started . "If you need access to the HTTP status code returned you will find it at RestResponse.StatusCode"Mainis
J
4

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.

Jernigan answered 9/10, 2014 at 14:51 Comment(1)
The given link yields no example as expectedKuth
W
1

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

Washbasin answered 6/5, 2021 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.