status response from client.DownloadDataAsync

231 views
Skip to first unread message

Leo Souza

unread,
Aug 11, 2022, 2:05:18 PM8/11/22
to RestSharp
Hi. I am using RestSharp for the first time as I need to send multiples pdf files to a rest API as a multpartformdata.

I am using client.DownloadDataAsync to get the API response, but I am not able to check the correct response code.

I have set "ThrowOnAnyError = true" client options but even when an error occurs in API processing it is not throwing any error. For example, even if I set an incorrect API route,  some bynary data is being sent back in my response, and as I can not teste its response code I am getting error when processing it.

So, how can I teste the response code after client.DownloadDataAsync ?

Thanks!

francois.g...@gmail.com

unread,
Aug 11, 2022, 5:50:07 PM8/11/22
to RestSharp
RestSharp and  DownloadDataTaskAsync is not same.

var client = new WebClient();
var data = await client.DownloadDataTaskAsync(new Uri(imageUrl));
await outstream.WriteAsync(data, 0, data.Length);
exemple here. 
https://stackoverflow.com/questions/1585985/how-to-use-the-webclient-downloaddataasync-method-in-this-context

I send to Chorus in France PDF zsipped in Json with RestShap. 

Leo Souza

unread,
Aug 11, 2022, 6:26:36 PM8/11/22
to RestSharp
Thanks. I will try it.
Reply all
Reply to author
Forward
0 new messages