Boost::asio

Hi all, I have problem while sending HTTP request with header by boost::asio, if somebody has done it before please give some exeample. When I send this request to dropbox I got response with error code. I have used example in boost http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/example/cpp03/http/client/async_client.cpp , I have only added 2 headers in constructor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Constructor
client(boost::asio::io_service& io_service,
      const std::string& server, const std::string& path)
    : resolver_(io_service),
      socket_(io_service)
  {
    // Form the request. We specify the "Connection: close" header so that the
    // server will close the socket after transmitting the response. This will
    // allow us to treat all data up until the EOF as the content.
    std::ostream request_stream(&request_);
    request_stream << "POST " << path << " HTTP/1.0\r\n";
    request_stream << "Host: " << server << "\r\n";
   
	request_stream << "Content-Type: application/x-www-form-urlencoded\r\n";
	request_stream << "Authorization: OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\", "
				   <<"oauth_consumer_key=\"<key>\", "
				   <<"oauth_signature=\"<secret>&\"\r\n";
	
	
	request_stream << "Accept: */*\r\n";
	request_stream << "Connection: close\r\n\r\n";
    // Start an asynchronous resolve to translate the server and service names
    // into a list of endpoints.
    tcp::resolver::query query(server, "https");
    resolver_.async_resolve(query,
        boost::bind(&client::handle_resolve, this,
          boost::asio::placeholders::error,
          boost::asio::placeholders::iterator));
  }


Last edited on
I have only added 2 headers in constructor.

You also changed the port from http to https.

In any case, this isn't an asio issue, it's a protocol issue: if you netcat the same strings to the same port, you should receive the same error code (which one was it?).
If you really mean to use https, take a look at the example at http://www.boost.org/doc/libs/release/doc/html/boost_asio/example/cpp03/ssl/client.cpp A higher-level library such as cpp-netlib would make this much easier.
Last edited on
Yes you're right, but at first I wrote http than I've changed to https, but in both states the result is the same, I'm receiving error code 400.
Topic archived. No new replies allowed.