Click here to Skip to main content
12,068,520 members (66,282 online)
Rate this:
 
Please Sign up or sign in to vote.
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 3-Dec-11 7:40am
Comments
Shakti Misra 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 3 Dec 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100