I want to download files with the TRESTClient library. However on some files I get the following error on the line of RESTRequest1.Execute:
Project dllhst3g.exe raised exception class ERESTException with message 'REST request failed: Keine Zuordnung für Unicode-Zeichen in der Multibyte-Zielcodeseite vorhanden'.
English:
No mapping for unicode character exists in target multi-byte code page
According to Fiddler, the request is sent and gets a response, which is a perfectly readable text file(Content-Type: text/plain). This looks like an encoding issue during the creation of the TRESTResponse object. The Content-Disposition response header is UTF-8 encoded, maybe that's the reason?:
Content-Disposition: attachment; filename*=utf-8''my%20%28filename%29.TXT
My code looks like this:
var
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTClient1 := TRESTClient.Create(myUrl);
RESTRequest1 := TRESTRequest.Create(RESTClient1);
RESTRequest1.AddAuthParameter('Authorization', 'Bearer ' + mySessionId, pkHTTPHEADER, [poDoNotEncode]);
RESTRequest1.AddParameter('Accept', 'application/octet-stream', pkHTTPHEADER, [poDoNotEncode]);
RESTRequest1.Execute;
if RESTRequest1.Response.StatusCode <> 200 then
begin
// raise Exception
end;
result := RESTRequest1.Response.RawBytes;
How can I make sure that the response uses the correct encoding?
Since I couldn´t find a solution with the
TRESTClientlibrary, I´ll use Indy for now as a workaround: