restbed
restbed copied to clipboard
request set_body doesn't send any data
If I run this code (taken from the examples) and add a POST method with set_body() it sends the requests to the server, but the request body arrives empty. Is this a known issue?
auto request = std::make_shared< restbed::Request >( restbed::Uri( url.toString() ) );
request->set_header( "Accept", "*/*" );
request->set_header( "Host", url.host );
request->set_method( "POST" );
request->set_body( "{ test: 1 }" );
auto response = restbed::Http::sync( request );
restbed::print( response );
auto future = restbed::Http::async( request, []( const shared_ptr< restbed::Request >, const shared_ptr< restbed::Response > response ) {
fprintf( stderr, "Printing async response\n" );
restbed::print( response );
} );
future.wait();
Sorry my bad, neded to add Content-Length to request: something like this:
request->set_header( "Content-Length", std::to_string(data.size()) );