Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am new user of Boost
I wanted to connect to a http web site by proxy
and want to download "www.boost.org/LICENSE_1_0.txt" this file.
it is telling connected
but not able to download the link above and also not able to maintain the connection.

here is my code.

try{ 
io_service i; 
tcp::socket t( i ); 
//ssl::context c( i, ssl::context::sslv3_client ); 
//ssl::stream<tcp::socket&> s( t, c ); 

tcp::resolver r( i ); 
tcp::resolver::query q( "192.168.1.1", "3128" ); 
t.connect( *r.resolve( q ) ); 
const char request[] = "CONNECT www.boost.org HTTP/1.0\r\n Connection: keep-alive \r\n\r\n"; 
//to keep the conn alive  "Connection: keep-alive" but :( 
boost::asio::write( t, buffer( request, sizeof request - 1 ) ); 
boost::asio::streambuf res; 
boost::asio::read_until( t, res, "\r\n\r\n" ); 
cout << &res; // => "HTTP/1.0 200 Connection established\r\n\r\n"  coming :) 


//now I want download www.boost.org/LICENSE_1_0.txt 
const char request1[]= "GET /LICENSE_1_0.txt HTTP/1.0 \r\n  Host: www.boost.org  \r\n Accept: */*\r\n Connection: keep-alive \r\n\r\n" ; 
boost::asio::write( t, buffer( request1, sizeof request1 - 1 ) ); 
boost::asio::read_until( t, res, "\r\n\r\n" ); 
cout << &res;//it is coming into catch block and printing  "Exception: read_unti: end of file"

} 
  catch (std::exception& e) 
  { 
    std::cout << "Exception: " << e.what() << "\n"; 
  } 
Posted
Comments
BrainlessLabs.com 14-Dec-11 1:16am    
What is the exception you are getting?
May be this
http://en.highscore.de/cpp/boost/asio.html
will help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900