bool HttpClient::SendRequest( const string& rServer, const string& rPath, boost::asio::ip::tcp::iostream& rStream ) { // Establish a connection to the server. m_sigInfoLog( "Connect to " + rServer ); rStream.connect( rServer, "http" ); if( !rStream ) { m_sigErrorLog( "Unable to connect: " + rStream.error().message() ); return false; } // Send the request. m_sigInfoLog( "Request paget " + rPath ); rStream << "GET " << rPath << " HTTP/1.0\r\n"; rStream << "Host: " << rServer << "\r\n"; rStream << "Referer: " << rServer << "\r\n"; rStream << "Accept: */*\r\n" << "Connection: close\r\n\r\n"; return true; }
bool HTTPSourceImpl::handshake(string const& url, int timeout) { // REMARK ASIO 1.5.1 // m_stream.expires_from_now(boost::posix_time::seconds(timeout)); m_stream.connect(url, "http"); if (!m_stream) { cout << "Unable to connect\n "; return false; } string data = "/LICENSE_1_0.txt"; m_stream << "GET " << data << " HTTP/1.0\r\n"; m_stream << "Host: " << url << "\r\n"; m_stream << "Accept: */*\r\n"; m_stream << "Connection: close\r\n\r\n"; string http_version; m_stream >> http_version; unsigned int status_code; m_stream >> status_code; string status_message; getline(m_stream, status_message); if (!m_stream || http_version.substr(0, 5) != "HTTP/") { cout << status_message; return false; } if (status_code != 200) { std::cout << "Response returned with status code " << status_code << "\n"; return false; } #if 1 // Process the response headers, which are terminated by a blank line. std::string header; while (std::getline(m_stream, header) && header != "\r") std::cout << header << "\n"; std::cout << "\n"; #endif return true; }
streamsize HTTPSourceImpl::read(char* s, streamsize n) { m_stream.read(s, n); return m_stream.gcount(); }