How to open a file received as a binary content in the HTTP body using RestSharp in it's associated editor
c#, rest, restsharp
Solution
It's one year late, but recently i've searched answer for OP question and found it - just replace last line of your code:
byte[] bytes = client.DownloadData(restRq);
If You want to have also an IRestResponse, then You can get RawBytes by:
IRestResponse rest = client.Execute(restRq);
byte[] bytes = rest.RawBytes;
More interesting methods explained in RestSharp source.
Problem
As per the requirement, I've to call the REST service which will send back an attachment or a file as a binary content of the file in the HTTP body and the appropriate value of the content-type header and i need to open the contents in it's specific editor. I'm using RestSharp and below is the code for the same: For eg. if the attachment is .doc- ``` var client = new RestClient(Properties.Settings.Default.RestServicesUrl + Constants.RestTicketServices); var restRq = new RestRequest(Constants.SearchTicket); restRq.Method = Method.GET; restRq.RequestFormat = DataFormat.Json; restRq.AddParameter("account_id", "10"); client.Authenticator = new HttpBasicAuthenticator(Properties.Settings.Default.RestAuthenticationUserName, Properties.Settings.Default.RestAuthenticationPass); IRestResponse rest = client.Execute(restRq); ``` So, after this call: ``` rest.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8" rest.Content = has binary data for the word document ``` and so on.... Basically, I'm looking how i can read the binary contents and open the same in the associated editor. .xls - Excel .doc - Word .pdf - Adobe and so on.....