restbed icon indicating copy to clipboard operation
restbed copied to clipboard

request set_body doesn't send any data

Open ziocleto opened this issue 9 years ago • 1 comments

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

ziocleto avatar Oct 04 '17 08:10 ziocleto

Sorry my bad, neded to add Content-Length to request: something like this:

request->set_header( "Content-Length", std::to_string(data.size()) );

ziocleto avatar Oct 04 '17 11:10 ziocleto