ASIO simple HTTP Test example

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.