{"id":226557,"date":"2014-06-18T11:55:02","date_gmt":"2014-06-18T07:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=226557"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=226557","title":{"rendered":"<span class=\"post_title\">\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e HTTP-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c \u0434\u043b\u044f \u0421++<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u044f\u0437\u044b\u043a\u0430 \u0421++ \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c HTTP. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f, \u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0451\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c REST-\u0441\u0435\u0440\u0432\u0438\u0441, \u043f\u0440\u043e\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0443, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0438\u043b\u0438 \u043a\u0440\u0430\u0443\u043b\u0435\u0440\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u00ab\u0410 \u043a\u0430\u043a\u0443\u044e \u0436\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432\u0437\u044f\u0442\u044c, \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u043f\u043e\u043f\u0440\u043e\u0449\u0435?\u00bb. \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a (\u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e) \u0438 \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u00ab\u0410 \u043a\u0430\u043a \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438?\u00bb. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0421++ \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0410 \u0441\u0430\u043c\u043e\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043e\u043a \u2014 \u0425\u0430\u0431\u0440: \u0438 \u0441\u0430\u043c \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0448\u044c, \u0438 \u0434\u0440\u0443\u0433\u0438\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u0411\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b:  <\/p>\n<ul>\n<li><b>WinInet<\/b><\/li>\n<li><b>Casablanca<\/b><\/li>\n<li><b>Qt<\/b><\/li>\n<li><b>POCO<\/b><\/li>\n<li><b>wxWidgets<\/b><\/li>\n<li><b>Boost.Asio<\/b><\/li>\n<li><b>libcurl<\/b><\/li>\n<li><b>neon<\/b><\/li>\n<li><b>.NET (\u0421++\/CLI)<\/b><\/li>\n<li><b><b>IXMLHTTPRequest<\/b><\/b><\/li>\n<li><b>HappyHttp<\/b><\/li>\n<li><b>cpp-netlib<\/b><\/li>\n<\/ul>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>WinInet<\/h4>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa385483(v=vs.85).aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa385483(v=vs.85).aspx<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: Windows 95 \u0438 \u0432\u044b\u0448\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\"> #include &lt;tchar.h&gt;     #include &lt;wininet.h&gt;        \/\/\/ ....      HINTERNET hIntSession =        ::InternetOpen(_T(&quot;MyApp&quot;), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);      HINTERNET hHttpSession =        InternetConnect(hIntSession, _T(&quot;api.twitter.com&quot;), 80, 0, 0, INTERNET_SERVICE_HTTP, 0, NULL);      HINTERNET hHttpRequest = HttpOpenRequest(       hHttpSession,        _T(&quot;GET&quot;),        _T(&quot;1\/statuses\/user_timeline.xml?screen_name=twitterapi&quot;),       0, 0, 0, INTERNET_FLAG_RELOAD, 0);      TCHAR* szHeaders = _T(&quot;Content-Type: text\/html\\nMySpecialHeder: whatever&quot;);     CHAR szReq[1024] = &quot;&quot;;     if( !HttpSendRequest(hHttpRequest, szHeaders, _tcslen(szHeaders), szReq, strlen(szReq))) {       DWORD dwErr = GetLastError();       \/\/\/ handle error     }      CHAR szBuffer[1025];     DWORD dwRead=0;     while(::InternetReadFile(hHttpRequest, szBuffer, sizeof(szBuffer)-1, &dwRead) && dwRead) {       szBuffer[dwRead] = 0;       OutputDebugStringA(szBuffer);       dwRead=0;     }      ::InternetCloseHandle(hHttpRequest);     ::InternetCloseHandle(hHttpSession);     ::InternetCloseHandle(hIntSession); <\/code><\/pre>\n<p>   <\/div>\n<\/div>\n<h5>Casablanca<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"https:\/\/casablanca.codeplex.com\">https:\/\/casablanca.codeplex.com<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">http_client client(L&quot;http:\/\/www.myhttpserver.com&quot;); http_request request(methods::GET); client.request(request).then([](http_response response)     {         \/\/ Perform actions here to inspect the HTTP response...         if(response.status_code() == status_codes::OK)         {         }     }); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>Qt<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/qt-project.org\">http:\/\/qt-project.org<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &quot;handler.h&quot;   Handler::Handler(QObject *parent) :QObject(parent)  {     http = new QHttp(this);     connect(http, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));     connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(responseHeaderReceived(QHttpResponseHeader)));     connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool))); }   void Handler::doHttp()  {     http-&gt;setHost(&quot;google.com&quot;);     http-&gt;get(&quot;\/&quot;); }   void Handler::stateChanged(int state)   {     switch(state)   {     case 0:         qDebug() &lt;&lt; &quot;Unconnected&quot;;         break;     case 1:         qDebug() &lt;&lt; &quot;Host Lookup&quot;;         break;     case 2:         qDebug() &lt;&lt; &quot;Connecting&quot;;         break;     case 3:         qDebug() &lt;&lt; &quot;Sending&quot;;         break;     case 4:         qDebug() &lt;&lt; &quot;Reading&quot;;         break;     case 5:         qDebug() &lt;&lt; &quot;Connect&quot;;         break;     case 6:         qDebug() &lt;&lt; &quot;Closing&quot;;         break;     } }   void Handler::responseHeaderReceived(const QHttpResponseHeader &resp)   {     qDebug() &lt;&lt; &quot;Size : &quot; &lt;&lt; resp.contentLength();     qDebug() &lt;&lt; &quot;Type : &quot; &lt;&lt; resp.contentType();     qDebug() &lt;&lt; &quot;Status Code : &quot; &lt;&lt; resp.statusCode(); }   void Handler::requestFinished(int id, bool error)   {     qDebug() &lt;&lt; &quot;Request Id : &quot; &lt;&lt; id;     if(error)   {         qDebug() &lt;&lt; &quot;Error&quot;;     }   else    {         qDebug() &lt;&lt; http-&gt;readAll();     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>POCO<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/pocoproject.org\">http:\/\/pocoproject.org<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;Poco\/Net\/HTTPClientSession.h&gt; #include &lt;Poco\/Net\/HTTPRequest.h&gt; #include &lt;Poco\/Net\/HTTPResponse.h&gt; #include &lt;Poco\/StreamCopier.h&gt; #include &lt;Poco\/Path.h&gt; #include &lt;Poco\/URI.h&gt; #include &lt;Poco\/Exception.h&gt; #include &lt;iostream&gt; #include &lt;string&gt;  using namespace Poco::Net; using namespace Poco; using namespace std;  int main(int argc, char **argv) {   if (argc != 2)   {     cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;uri&gt;&quot; &lt;&lt; endl;     cout &lt;&lt; &quot;       fetches the resource identified by &lt;uri&gt; and print it&quot; &lt;&lt; endl;     return -1;   }    try   {     \/\/ prepare session     URI uri(argv[1]);     HTTPClientSession session(uri.getHost(), uri.getPort());      \/\/ prepare path     string path(uri.getPathAndQuery());     if (path.empty()) path = &quot;\/&quot;;      \/\/ send request     HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);     session.sendRequest(req);      \/\/ get response     HTTPResponse res;     cout &lt;&lt; res.getStatus() &lt;&lt; &quot; &quot; &lt;&lt; res.getReason() &lt;&lt; endl;      \/\/ print response     istream &is = session.receiveResponse(res);     StreamCopier::copyStream(is, cout);   }   catch (Exception &ex)   {     cerr &lt;&lt; ex.displayText() &lt;&lt; endl;     return -1;   }    return 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>wxWidgets<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/www.wxwidgets.org\">http:\/\/www.wxwidgets.org<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;wx\/sstream.h&gt; #include &lt;wx\/protocol\/http.h&gt;   wxHTTP get; get.SetHeader(_T(&quot;Content-type&quot;), _T(&quot;text\/html; charset=utf-8&quot;)); get.SetTimeout(10); \/\/ 10 seconds of timeout instead of 10 minutes ...   \/\/ this will wait until the user connects to the internet. It is important in case of dialup (or ADSL) connections while (!get.Connect(_T(&quot;www.google.com&quot;)))  \/\/ only the server, no pages here yet ...     wxSleep(5);   wxApp::IsMainLoopRunning(); \/\/ should return true   \/\/ use _T(&quot;\/&quot;) for index.html, index.php, default.asp, etc. wxInputStream *httpStream = get.GetInputStream(_T(&quot;\/intl\/en\/about.html&quot;));   \/\/ wxLogVerbose( wxString(_T(&quot; GetInputStream: &quot;)) &lt;&lt; get.GetResponse() &lt;&lt; _T(&quot;-&quot;) &lt;&lt; ((resStream)? _T(&quot;OK &quot;) : _T(&quot;FAILURE &quot;)) &lt;&lt; get.GetError() );   if (get.GetError() == wxPROTO_NOERR) {     wxString res;     wxStringOutputStream out_stream(&res);     httpStream-&gt;Read(out_stream);       wxMessageBox(res);     \/\/ wxLogVerbose( wxString(_T(&quot; returned document length: &quot;)) &lt;&lt; res.Length() ); } else {     wxMessageBox(_T(&quot;Unable to connect!&quot;)); }   wxDELETE(httpStream); get.Close(); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>Boost.Asio<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/www.boost.org\/doc\/libs\/1_55_0\/doc\/html\/boost_asio.html\">http:\/\/www.boost.org\/doc\/libs\/1_55_0\/doc\/html\/boost_asio.html<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;istream&gt; #include &lt;ostream&gt; #include &lt;string&gt; #include &lt;boost\/asio.hpp&gt;  using boost::asio::ip::tcp;  int main(int argc, char* argv[]) {   try   {     if (argc != 3)     {       std::cout &lt;&lt; &quot;Usage: sync_client &lt;server&gt; &lt;path&gt;\\n&quot;;       std::cout &lt;&lt; &quot;Example:\\n&quot;;       std::cout &lt;&lt; &quot;  sync_client www.boost.org \/LICENSE_1_0.txt\\n&quot;;       return 1;     }      boost::asio::io_service io_service;      \/\/ Get a list of endpoints corresponding to the server name.     tcp::resolver resolver(io_service);     tcp::resolver::query query(argv[1], &quot;http&quot;);     tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);      \/\/ Try each endpoint until we successfully establish a connection.     tcp::socket socket(io_service);     boost::asio::connect(socket, endpoint_iterator);      \/\/ Form the request. We specify the &quot;Connection: close&quot; header so that the     \/\/ server will close the socket after transmitting the response. This will     \/\/ allow us to treat all data up until the EOF as the content.     boost::asio::streambuf request;     std::ostream request_stream(&request);     request_stream &lt;&lt; &quot;GET &quot; &lt;&lt; argv[2] &lt;&lt; &quot; HTTP\/1.0\\r\\n&quot;;     request_stream &lt;&lt; &quot;Host: &quot; &lt;&lt; argv[1] &lt;&lt; &quot;\\r\\n&quot;;     request_stream &lt;&lt; &quot;Accept: *\/*\\r\\n&quot;;     request_stream &lt;&lt; &quot;Connection: close\\r\\n\\r\\n&quot;;      \/\/ Send the request.     boost::asio::write(socket, request);      \/\/ Read the response status line. The response streambuf will automatically     \/\/ grow to accommodate the entire line. The growth may be limited by passing     \/\/ a maximum size to the streambuf constructor.     boost::asio::streambuf response;     boost::asio::read_until(socket, response, &quot;\\r\\n&quot;);      \/\/ Check that response is OK.     std::istream response_stream(&response);     std::string http_version;     response_stream &gt;&gt; http_version;     unsigned int status_code;     response_stream &gt;&gt; status_code;     std::string status_message;     std::getline(response_stream, status_message);     if (!response_stream || http_version.substr(0, 5) != &quot;HTTP\/&quot;)     {       std::cout &lt;&lt; &quot;Invalid response\\n&quot;;       return 1;     }     if (status_code != 200)     {       std::cout &lt;&lt; &quot;Response returned with status code &quot; &lt;&lt; status_code &lt;&lt; &quot;\\n&quot;;       return 1;     }      \/\/ Read the response headers, which are terminated by a blank line.     boost::asio::read_until(socket, response, &quot;\\r\\n\\r\\n&quot;);      \/\/ Process the response headers.     std::string header;     while (std::getline(response_stream, header) && header != &quot;\\r&quot;)       std::cout &lt;&lt; header &lt;&lt; &quot;\\n&quot;;     std::cout &lt;&lt; &quot;\\n&quot;;      \/\/ Write whatever content we already have to output.     if (response.size() &gt; 0)       std::cout &lt;&lt; &response;      \/\/ Read until EOF, writing data to output as we go.     boost::system::error_code error;     while (boost::asio::read(socket, response,           boost::asio::transfer_at_least(1), error))       std::cout &lt;&lt; &response;     if (error != boost::asio::error::eof)       throw boost::system::system_error(error);   }   catch (std::exception& e)   {     std::cout &lt;&lt; &quot;Exception: &quot; &lt;&lt; e.what() &lt;&lt; &quot;\\n&quot;;   }    return 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>libcurl<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/curl.haxx.se\/libcurl\">http:\/\/curl.haxx.se\/libcurl<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;curl\/curl.h&gt;   int main(void) {   CURL *curl;   CURLcode res;     curl = curl_easy_init();   if(curl) {     curl_easy_setopt(curl, CURLOPT_URL, &quot;http:\/\/example.com&quot;);     \/* example.com is redirected, so we tell libcurl to follow redirection *\/      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);       \/* Perform the request, res will get the return code *\/      res = curl_easy_perform(curl);     \/* Check for errors *\/      if(res != CURLE_OK)       fprintf(stderr, &quot;curl_easy_perform() failed: %s\\n&quot;,               curl_easy_strerror(res));       \/* always cleanup *\/      curl_easy_cleanup(curl);   }   return 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>neon<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/www.webdav.org\/neon\">http:\/\/www.webdav.org\/neon<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;ne_session.h&gt; #include &lt;ne_request.h&gt; #include &lt;ne_utils.h&gt; #include &lt;ne_uri.h&gt;  int httpResponseReader(void *userdata, const char *buf, size_t len) {     string *str = (string *)userdata;     str-&gt;append(buf, len);     return 0; }   int do_get(string host) {     ne_session *sess;     ne_request *req;     string response;       ne_sock_init();       sess = ne_session_create(&quot;http&quot;, host.c_str(), 80);     ne_set_useragent(sess, &quot;MyAgent\/1.0&quot;);       req = ne_request_create(sess, &quot;GET&quot;, &quot;\/SomeURL\/method?with=parameter&value=data&quot;);     \/\/ if accepting only 2xx codes, use &quot;ne_accept_2xx&quot;     ne_add_response_body_reader(req, ne_accept_always, httpResponseReader, &response);       int result = ne_request_dispatch(req);     int status = ne_get_status(req)-&gt;code;       ne_request_destroy(req);       string errorMessage = ne_get_error(sess);     ne_session_destroy(sess);       printf(&quot;result %d, status %d\\n&quot;, result, status);     cout &lt;&lt; response &lt;&lt; &quot;\\n&quot;;       switch (result) {     case NE_OK:         break;     case NE_CONNECT:         throw ConnectionError(errorMessage);     case NE_TIMEOUT:         throw TimeOutError(errorMessage);     case NE_AUTH:         throw AuthenticationError(errorMessage);     default:         throw AnotherWebError(errorMessage);     }       return 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>.NET<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.net.httpwebrequest.aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/system.net.httpwebrequest.aspx<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: Windows XP \u0438 \u0432\u044b\u0448\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#using &lt;System.dll&gt;  using namespace System; using namespace System::Net; using namespace System::Text; using namespace System::IO;  \/\/ Specify the URL to receive the request. int main() {    array&lt;String^&gt;^args = Environment::GetCommandLineArgs();    HttpWebRequest^ request = dynamic_cast&lt;HttpWebRequest^&gt;(WebRequest::Create( args[ 1 ] ));     \/\/ Set some reasonable limits on resources used by this request    request-&gt;MaximumAutomaticRedirections = 4;    request-&gt;MaximumResponseHeadersLength = 4;     \/\/ Set credentials to use for this request.    request-&gt;Credentials = CredentialCache::DefaultCredentials;    HttpWebResponse^ response = dynamic_cast&lt;HttpWebResponse^&gt;(request-&gt;GetResponse());    Console::WriteLine( &quot;Content length is {0}&quot;, response-&gt;ContentLength );    Console::WriteLine( &quot;Content type is {0}&quot;, response-&gt;ContentType );     \/\/ Get the stream associated with the response.    Stream^ receiveStream = response-&gt;GetResponseStream();     \/\/ Pipes the stream to a higher level stream reader with the required encoding format.     StreamReader^ readStream = gcnew StreamReader( receiveStream,Encoding::UTF8 );    Console::WriteLine( &quot;Response stream received.&quot; );    Console::WriteLine( readStream-&gt;ReadToEnd() );    response-&gt;Close();    readStream-&gt;Close(); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>IXMLHTTPRequest<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms759148(v=vs.85).aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/ms759148(v=vs.85).aspx<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: Windows XP \u0438 \u0432\u044b\u0448\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;atlbase.h&gt; #include &lt;msxml6.h&gt;  HRESULT hr; CComPtr&lt;IXMLHTTPRequest&gt; request;  hr = request.CoCreateInstance(CLSID_XMLHTTP60); hr = request-&gt;open(     _bstr_t(&quot;GET&quot;),     _bstr_t(&quot;https:\/\/www.google.com\/images\/srpr\/logo11w.png&quot;),     _variant_t(VARIANT_FALSE),     _variant_t(),     _variant_t()); hr = request-&gt;send(_variant_t());  \/\/ get status - 200 if succuss long status; hr = request-&gt;get_status(&status);  \/\/ load image data (if url points to an image) VARIANT responseVariant; hr = request-&gt;get_responseStream(&responseVariant); IStream* stream = (IStream*)responseVariant.punkVal; CImage *image = new CImage(); image-&gt;Load(stream); stream-&gt;Release(); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>HappyHttp<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/scumways.com\/happyhttp\/happyhttp.html\">http:\/\/scumways.com\/happyhttp\/happyhttp.html<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">static int count=0;  \/\/ invoked when response headers have been received void OnBegin( const happyhttp::Response* r, void* userdata ) { \tprintf( &quot;BEGIN (%d %s)\\n&quot;, r-&gt;getstatus(), r-&gt;getreason() ); \tcount = 0; }  \/\/ invoked to process response body data (may be called multiple times) void OnData( const happyhttp::Response* r, void* userdata, const unsigned char* data, int n ) { \tfwrite( data,1,n, stdout ); \tcount += n; }  \/\/ invoked when response is complete void OnComplete( const happyhttp::Response* r, void* userdata ) { \tprintf( &quot;COMPLETE (%d bytes)\\n&quot;, count ); }   void TestGET() { \thappyhttp::Connection conn( &quot;www.scumways.com&quot;, 80 ); \tconn.setcallbacks( OnBegin, OnData, OnComplete, 0 );  \tconn.request( &quot;GET&quot;, &quot;\/happyhttp\/test.php&quot; );  \twhile( conn.outstanding() ) \t\tconn.pump(); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>cpp-netlib<\/h5>\n<p>  <b>\u0421\u0430\u0439\u0442<\/b>: <a href=\"http:\/\/cpp-netlib.org\">http:\/\/cpp-netlib.org<\/a><br \/>  <b>\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430<\/b>: \u0432\u0441\u0435  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">using namespace boost::network; using namespace boost::network::http;  client::request request_(&quot;http:\/\/127.0.0.1:8000\/&quot;); request_ &lt;&lt; header(&quot;Connection&quot;, &quot;close&quot;); client client_; client::response response_ = client_.get(request_); std::string body_ = body(response_); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0422\u0430\u043a, \u0441\u043a\u0430\u0436\u0438 \u0443\u0436\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c!<\/h4>\n<p>  \u0425\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0439 \u0433\u043e\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0438 \u2014 \u0431\u0435\u0440\u0438\u0442\u0435 libcurl. \u041f\u0438\u0448\u0435\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u2014 \u0431\u0435\u0440\u0438\u0442\u0435 Qt. \u0425\u043e\u0442\u0438\u0442\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0421++11 \u2014 \u0431\u0435\u0440\u0438\u0442\u0435 Casablanca. \u041f\u0438\u0448\u0435\u0442\u0435 \u043f\u043e\u0434 .NET \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u041f\u0438\u0448\u0435\u0442\u0435 \u0447\u0442\u043e-\u0442\u043e \u0431\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438 \u043a\u0440\u043e\u043c\u0435 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u2014 Boost \u0438\u043b\u0438 POCO.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/company\/infopulse\/blog\/226557\/\"> http:\/\/habrahabr.ru\/company\/infopulse\/blog\/226557\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u044f\u0437\u044b\u043a\u0430 \u0421++ \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c HTTP. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f, \u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0451\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c REST-\u0441\u0435\u0440\u0432\u0438\u0441, \u043f\u0440\u043e\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0443, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0438\u043b\u0438 \u043a\u0440\u0430\u0443\u043b\u0435\u0440\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u00ab\u0410 \u043a\u0430\u043a\u0443\u044e \u0436\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432\u0437\u044f\u0442\u044c, \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u043f\u043e\u043f\u0440\u043e\u0449\u0435?\u00bb. \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a (\u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e) \u0438 \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u00ab\u0410 \u043a\u0430\u043a \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438?\u00bb. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0421++ \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0410 \u0441\u0430\u043c\u043e\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043e\u043a \u2014 \u0425\u0430\u0431\u0440: \u0438 \u0441\u0430\u043c \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0448\u044c, \u0438 \u0434\u0440\u0443\u0433\u0438\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u0411\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b:  <\/p>\n<ul>\n<li><b>WinInet<\/b><\/li>\n<li><b>Casablanca<\/b><\/li>\n<li><b>Qt<\/b><\/li>\n<li><b>POCO<\/b><\/li>\n<li><b>wxWidgets<\/b><\/li>\n<li><b>Boost.Asio<\/b><\/li>\n<li><b>libcurl<\/b><\/li>\n<li><b>neon<\/b><\/li>\n<li><b>.NET (\u0421++\/CLI)<\/b><\/li>\n<li><b><b>IXMLHTTPRequest<\/b><\/b><\/li>\n<li><b>HappyHttp<\/b><\/li>\n<li><b>cpp-netlib<\/b><\/li>\n<\/ul>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-226557","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/226557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=226557"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/226557\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=226557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=226557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=226557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}