#include <iostream>
#include <fstream>
#include <string>
#include <boost/asio.hpp>
using namespace Std;
using namespace Boost::asio;
int Httptest ()
{
Io_service Iosev;
Ip::tcp::socket socket (Iosev);
Ip::tcp::endpoint EP (Ip::address_v4::from_string ("192.168.0.88"), 8080);
Boost::system::error_code EC;
Socket.connect (EP, EC);
if (EC) return-1;
BOOST::ASIO::STREAMBUF request;
Std::ostream Request_stream (&request);
Request_stream << "get/cs/restfull/operationrestfullapi/testget/http/1.1\r\n";
Request_stream << "Accept:application/x-ms-application, Image/jpeg, Application/xaml+xml, Image/gif, image/ Pjpeg, APPLICATION/X-MS-XBAP, Application/vnd.ms-excel, Application/vnd.ms-powerpoint, Application/msword, */*\r\n " ;
Request_stream << "accept-language:zh-cn\r\n";
Request_stream << "user-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; trident/4.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729; Media Center PC 6.0;. net4.0c;. net4.0e; infopath.3) \ r \ n ";
Request_stream << "Host:" << "192.168.0.88:8080" << "\ r \ n";
Request_stream << "connection:keep-alive\r\n";
Boost::asio::write (socket, request);
Char buf[1024] = {0};
size_t len = socket.read_some (buffer (BUF), EC);
Ofstream OFS;
Ofs.open ("Httpresponse.txt");
OFS << buf << Endl;
Ofs.close ();
return 0;
}
ASIO simple HTTP Test example