处理非文本数据时,
我正在使用RAD Studio C++Builder,我需要从REST API检索一个PDF文件。
用Postman网站测试,在回复的正文中我看到PDF很好,可以保存它。
通过C++Builder,我无法保存PDF。
这是我的代码:
TFileStream *FStream;
FStream = new TFileStream("c:\tmp\test.pdf", fmCreate);
FStream->Write(this->RESTResponse1->Content.c_str(), RESTResponse1->ContentLength);
delete FStream;
以下是API的回复:
Connection=keep-alive
Date=Wed, 19 Oct 2022 13:17:11 GMT
Content-Length=15891
Content-Type=application/pdf
Vary=Origin
Content-Disposition=attachment; filename*=utf-8''-HUGO-concentr%C3%A9_bien-%C3%AAtre-Maux_de_t%C3%AAte-8ml-de0752a5-21c4-49a6-9fa7-1183e9f1ed0d.pdf
X-Frame-Options=DENY
X-Content-Type-Options=nosniff
Referrer-Policy=same-origin
Strict-Transport-Security=max-age=15724800; includeSubDomains
如何获取文件或文件内容并保存?
TRESTResponse::Content
属性是错误的读取选项。请改用TRESTResponse::RawBytes
属性。