I am calling an API in Delphi the response of which is a pdf file. I am getting IHttpResponse, with MimeType application-pdf. How can I create a pdf file from this response?
Code:
response := Form1.NetHTTPClient1.Post(apiurl,parametres, nil, headerparams);
responsestring := response.ContentAsString(tencoding.UTF8);
Form1.memo.Lines.Add(responsestring);
When I try to convert the response to ContentAsString the below error is coming:
I even tried to pass a TStream Object in the post request:
response := Form1.NetHTTPClient1.Post(apiurl,parametres, resStream, headerparams);
responsestring := response.ContentAsString(tencoding.UTF8);
Form1.memo.Lines.Add(responsestring);
But the value of resStream is '' after Post call. The response code is coming 200 which means I am getting a response.
In Postman when I try this, I get a pdf file in response.

You can't treat a binary PDF file as a UTF-8 string, which is why
ContentAsString()is failing with an encoding error.Per the
TNetHttpClient.Post()documentation:So, either of these approaches should work fine:
If they do not work for you, you will need to file a bug report with Embarcadero.