1

iam developing a rest service in c++ for a wordpress client in a project for a further education. The service is written in c++ using casablanca as framework for and service and client communicate over JSON.

Now I have to send PDF Files to each other. Can sb. tell me a method or an example to do this without sending direct links for a download?

http://casablanca.codeplex.com/

Here is my function to start the server and add the support methods.

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

And an example of sending a JSON response to my client.

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();
}
Cazzador
  • 33
  • 2
  • 9
  • Welcome to Stack Overflow! In general "what's the best method" questions aren't appropriate for this site. Can you show us the code you've tried? – Jack Guy Dec 09 '15 at 05:44
  • Here you are, now i need a possibility to send a PDF File via JSON to show it over Wordpress. – Cazzador Dec 10 '15 at 06:10

1 Answers1

0

Files can be send serialized in the body to the clients.

This is an example only with the File Date, no headers and nothing else.

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);
Cazzador
  • 33
  • 2
  • 9