My server handle looks like this:
class ServerHandle {
public:
ServerHandle(/* ... */){};
virtual ~ServerHandle(){};
void operator() (const server::request request, server::connection_ptr connection) {
std::string str = request.body;
std::cout << "'" << str << "'" << std::endl;
};
private:
//...
}
Here the complete file:
http://pastie.org/10799656
Do you know what I am doing wrong?
Regards,
Ferdinand
On 16 Apr 2016, at 20:42, Ferdinand Thiessen <f.thi...@gmx.de> wrote:Hello I have a very simple server, basically the example server.
I now want to get the body of the message (in my case json). The documentation says it should work with:
request.body or body(request).
But nothing of this works, the resulting string is always empty (I checked the client, but it is correctly sending the request).
My server handle looks like this:
class ServerHandle {
public:
ServerHandle(/* ... */){};
virtual ~ServerHandle(){};
void operator() (const server::request request, server::connection_ptr connection) {
std::string str = request.body;
std::cout << "'" << str << "'" << std::endl;
};
private:
//...
}
Here the complete file:
http://pastie.org/10799656
Do you know what I am doing wrong?
....
Huh, that part is true but really misleading. It works for the synchronous client implementation, because that's what used to be the default. For the asynchronous implementation we have now (the only one) in 0.12.0, this will always return an empty string.
So in the asynchronous client implementation, you're meant to interact with the connection. The latest documentation shows how to use the read function on the connection object:Does this help?
async_connection.hpp|395|error: no match for call to ‘(const read_callback_function {aka const std::function<void(boost::iterator_range<const char*>, std::error_code, long unsigned int, std::shared_ptr<boost::network::http::async_connection<boost::network::http::tags::http_server, {anonymous}::serverhandle> >)>}) (std::error_code&, size_t&)’|
[&body](server::connection::input_range ir, std::error_code ec, std::size_t s, server::connection_ptr con) {
body.append(ir.begin(), ir.end());
std::cout << " FO: " << std::distance(ir.begin(), ir.end()) << std::endl;
std::cout << "Size: " << s << " cont: ";
for (auto s : ir)
std::cout << s;
std::cout << " END!!!" << std::endl;
});--
You received this message because you are subscribed to the Google Groups "The C++ Network Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpp-netlib+...@googlegroups.com.
To post to this group, send email to cpp-n...@googlegroups.com.
Visit this group at https://groups.google.com/group/cpp-netlib.
For more options, visit https://groups.google.com/d/optout.