Skip to content

POST request body is empty (cpp-netlib 0.13.0) #823

Open

Description

@ksl67

I have upgraded cpp-netlib from v0.11.0 to 0.13.0 and run into some difficulties.

Previously, when a request was sent to the server, the body of the request could be read from the request object.

The request body is now empty when I send the same request to a server using v0.13.0.

The rest of the request object appears to be correct - only the body is empty.

Is there something I need to do differently? I can't find any examples on the site that show how the body is extracted.

I have confirmed the same behaviour from the hello world example.

#include <boost/network/protocol/http/server.hpp>
#include <iostream>

namespace http = boost::network::http;

struct hello_world;
typedef http::server<hello_world> server;

struct hello_world
{
    void operator()(const server::request  &request, server::connection_ptr connection)
    {
        ///////////////////////////////////
        // request.body is empty
        ///////////////////////////////////

        server::string_type ip = source(request);
        unsigned int port = request.source_port;

        std::ostringstream data;
        data << "Hello, " << ip << ':' << port << '!';
        connection->set_status(server::connection::ok);
        connection->write(data.str());
    }
};

int main(int argc, char *argv[]) {

    try {
        hello_world handler;
        server::options options(handler);
        server server_(options.address("192.168.0.19").port("9999"));

        server_.run();
    }
    catch (std::exception &e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }

    return 0;
}

Here is the request I'm sending:

curl -v -X POST http://192.168.0.19:9999/my-app/rest/foo/1.0/bar -H 'Content-Type: application/x-www-form-urlencoded' --data key=value

Activity

  1. carun commented on Feb 23, 2018

    @carun

    Synchronous server is apparently not available in 0.13-release branch. So you need to receive the data asynchronously. This comment here is more related #809 (comment)

    @deanberris any thoughts? I have seen this request from others as well. Is there anyway to achieve this without using the async read?

  2. ksl67 commented on Feb 23, 2018

    @ksl67
    Author

    @carun Is there an example anywhere that is more associated with the hello world example. I can't see how to apply that file uploader example to this.

    Why remove this feature and not mention it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions