-->

HttpStatus and DownloadData

2020-08-12 04:10发布

问题:

I'm trying to download a file (an image) with RestSharp using the DownloadData method

var client = new RestClient(baseUrl);

var request = new RestRequest("GetImage", Method.GET);

var response = client.DownloadData(request);

This works fine, but if the requests returns an error I cannot see the HttpStatus code.

I could make a Request and check the status:

var client = new RestClient(baseUrl);

var request = new RestRequest("GetImage", Method.GET);

var response = client.Execute(request);

var status = response.StatusCode;

But then I cannot get the image from the Content property.

I'm I missing something obvious?

回答1:

The image data would be in RestResponse.RawBytes



标签: c# restsharp