我在Ubuntu Linux上的服务器上使用cpprest。到目前为止,我能够处理请求,并使用JSON响应进行回复。
我接受的其中一个请求需要使用PDF文件进行响应。我看到http_request类有一个接受异步流的reply()方法。对于我的生活,我不知道如何将这个流与我在磁盘上的PDF文件相关联。
utility::string_t pdfFilename = getPdfFilename();
concurrency::streams::istream stream; // how do associate my pdfFilename?
request.reply(web::http::status_codes::OK, stream, "application/pdf");发布于 2019-07-04 20:07:59
我希望你已经弄明白了。下面是我如何回复本地pdf文件
void replyPdf(web::http::http_request message, string_t file_name)
{
concurrency::streams::fstream::open_istream(file_name, std::ios::in)
.then([=](concurrency::streams::istream is)
{
web::http::http_response response(web::http::status_codes::OK);
response.headers().add(L"Content-Disposition", U("inline; filename = \"") + file_name + U("\""));
response.set_body(std::move(is), U("application/pdf"));
message.reply(response).then([](pplx::task<void> t) {});
});
}https://stackoverflow.com/questions/52620010
复制相似问题