Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ socket Web Boost Sockets , +
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 at 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
0 Maciej Los 295
1 OriginalGriff 273
2 Aajmot Sk 234
3 Marcin Kozub 205
4 Richard MacCutchan 200
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 3 Dec 2011
Copyright © CodeProject, 1999-2014
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