#include <boost/asio.hpp>
#include <iostream>
#include <boost/foreach.hpp>
#include <string>
#include <sstream>
#include <exception>
#include <iterator>
#include <functional>
#include <algorithm>
#include <fstream>
std::string Get_Http_1_1(std::string uri)
{
std::ostringstream request;
request<<"GET ";
request<<uri;
request<<" HTTP/1.1/n";
request<<"Connection:close /n/n";
return request.str();
}
int main(int argc, char* argv[])
{
try
{
boost::asio::ip::tcp::iostream netstream("google.cn","www");
netstream<<Get_Http_1_1("www.google.cn/index.html")<<std::flush;
std::ofstream out_file("index.html");
netstream>>out_file.rdbuf();
std::cout<<"receive data success"<<std::endl;
}
catch (const std::exception& e)
{
std::cout<<e.what()<<std::endl;
}
catch (...)
{
std::cout<<"unkown exception"<<std::endl;
}
}
#include <iostream>
#include <boost/foreach.hpp>
#include <string>
#include <sstream>
#include <exception>
#include <iterator>
#include <functional>
#include <algorithm>
#include <fstream>
std::string Get_Http_1_1(std::string uri)
{
std::ostringstream request;
request<<"GET ";
request<<uri;
request<<" HTTP/1.1/n";
request<<"Connection:close /n/n";
return request.str();
}
int main(int argc, char* argv[])
{
try
{
boost::asio::ip::tcp::iostream netstream("google.cn","www");
netstream<<Get_Http_1_1("www.google.cn/index.html")<<std::flush;
std::ofstream out_file("index.html");
netstream>>out_file.rdbuf();
std::cout<<"receive data success"<<std::endl;
}
catch (const std::exception& e)
{
std::cout<<e.what()<<std::endl;
}
catch (...)
{
std::cout<<"unkown exception"<<std::endl;
}
}