asio HTTP client example always returns error 400
Hi all. I copied the boost::asio HTTP client example code: http://live.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/clien... and just replaced the argv stuff with a hard-coded domain name and "index.html". It appears to make the socket connection OK, but the response to the request is 400 ("bad request"). Is there something wrong with this request? boost::asio::streambuf request; std::ostream request_stream(&request); request_stream << "GET " << "index.html" << " HTTP/1.0\r\n"; request_stream << "Host: " << "musicobsession.com" << "\r\n"; request_stream << "Accept: */*\r\n"; request_stream << "Connection: close\r\n\r\n"; It doesn't matter what host I use (as long is it's real). Thanks for any insight!
On Tue, Aug 24, 2010 at 3:38 PM, G S
I copied the boost::asio HTTP client example code: http://live.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/clien...
and just replaced the argv stuff with a hard-coded domain name and "index.html". It appears to make the socket connection OK, but the response to the request is 400 ("bad request").
OK, it turns out that it doesn't matter what I put as the host. This doesn't return an error: boost::asio::io_service io_service; // Get a list of endpoints corresponding to the server name. tcp::resolver resolver(io_service); tcp::resolver::query query("ksjfkdsjkfjds.com", "http"); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator end; // Try each endpoint until we successfully establish a connection. tcp::socket socket(io_service); boost::system::error_code error = boost::asio::error::host_not_found; while (error && endpoint_iterator != end) { socket.close(); socket.connect(*endpoint_iterator++, error); } What gives?
OK, well, it turns out that you have to have a slash in front of the name of the item you're trying to GET: request_stream << "GET " << "/index.html" << " HTTP/1.0\r\n"; Glad we had this time together...
On Wed, Aug 25, 2010 at 1:34 AM, G S
OK, well, it turns out that you have to have a slash in front of the name of the item you're trying to GET:
request_stream << "GET " << "/index.html" << " HTTP/1.0\r\n";
Glad we had this time together...
Heh, yeah, standard http header stuff, most servers use a filesystem type structure, as such they need a root slash.
participants (2)
-
G S
-
OvermindDL1