C++ Casablanca Restservice将PDF文件发送给Wordpress客户端
问题描述:
iam在C++中为一个项目中的wordpress客户端开发一个休息服务以便进一步教育。 该服务是用C++编写的,使用casablanca作为框架,服务和客户端通过JSON进行通信。C++ Casablanca Restservice将PDF文件发送给Wordpress客户端
现在我必须发送PDF文件给对方。 可以。告诉我一种方法或示例,无需发送直接链接进行下载?
http://casablanca.codeplex.com/
这里是我的功能来启动服务器,并添加支持的方法。
void Commanagement::Init(utility::string_t url, utility::string_t port)
{
this->url = &url;
this->port = &port;
listener = new http_listener(U("http://localhost:4711"));
listener->support(methods::GET, std::bind(&Commanagement::handle_GET, this, std::placeholders::_1));
listener->support(methods::POST, std::bind(&Commanagement::handle_POST, this, std::placeholders::_1));
listener->open().wait();
}
并且向我的客户端发送JSON响应的示例。
void Commanagement::handle_POST(http_request message)
{
ucout << message.extract_json().wait();
auto paths = http::uri::split_path(http::uri::decode(message.relative_uri().path()));
json::value postData;
postData[L"id"] = json::value::number(13);
postData[L"FirstVal"] = json::value::string(L"Baseball");
postData[L"SomeVal"] = json::value::string(L"test");
message.reply(web::http::status_codes::OK, postData.serialize()).wait();
}
答
文件可以发送到客户端序列化。
这是一个只有文件日期的例子,没有头文件和其他东西。
ifstream Stream;
Stream.open(FullFileName,std::ios::binary);
string Content, Line;
if (Stream)
{
while (getline(Stream,Line))
{
Content += Line;
}
}
Stream.close();
Request::request->set_body(Content);
欢迎来到Stack Overflow!总的来说,“最好的方法是什么”问题不适合这个网站。你能告诉我们你试过的代码吗? – Harangue
在这里,现在我需要通过JSON发送PDF文件以在Wordpress上显示它的可能性。 – Cazzador