C++ Casablanca Restservice 将 PDF 文件发送到 Wordpress 客户端

C++ Casablanca Restservice send PDF Files to Wordpress Clients

我正在为一个继续教育项目中的 wordpress 客户端开发一个 C++ 的休息服务。 该服务是用 c++ 编写的,使用 casablanca 作为框架,服务和客户端通过 JSON.

进行通信

现在我必须互相发送 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();
}

文件可以在 body 中序列化发送给客户端。

这是一个仅包含文件日期的示例,没有 headers,没有其他任何内容。

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);