I use RestSharp in version 111.2.0. All our requests are build in this way:
internal async Task<byte[]> GetFileAsync(int documentId)
{
RestRequest request = new RestRequest($"{_apiPath}/document-files/{documentId}", Method.Get);
request.AddHeader("Accept", "application/octet-stream");
RestResponse response = await mRestClient.ExecuteAsync(request).ConfigureAwait(true);
ErrorHandling(response);
return response.RawBytes;
}
So, really simple approach. We have a handler written, that makes log files and so on in the ErrorHandling-method. When we donwload a file this way it is "corrupted" by the octet-stream headers. These headers are inside the Content and inside the RawBytes properties.
The file then looks like this:
--69d36367-8ab0-4b7c-a718-668f7542e836
Content-Type: application/octet-stream
Content-Disposition: form-data; name=""; filename="MG Test2.pdf"
%PDF-1.7
...
%%EOF
--69d36367-8ab0-4b7c-a718-668f7542e836--
But the beginning of the real file is the %PDF-1.7 and %%EOF should be the end of the file. Naturally I could cut it out by hand... but that is not really a good approach, is it? There are coursing some examples in the net for the downloading of files, using the DownloadDataAsync for example. But that does not return a Response but throws errors itself and would require a completely new handling and try catches, etc.
Btw... if I don't add the header by hand I get a 406 error. So it is needed.
Anyone an idea what could be a better way of getting the file than to cut it out myself of the response?
EDIT: Sorry, I found the error and that was on upload. The error only existed on files that I uploaded myself right before. I uploaded them with Request.AddFile(...) instead of Request.AddParameter(...) and that seemed to be the wrong way. I corrected that and now the error is gone.
--69d36367-8ab0-4b7c-a718-668f7542e836thrown by the server prevents RestSharp successful parsing