Created
October 1, 2017 13:04
-
-
Save spudro228/6732af3d261000643ed15c6733fcf2c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BOOST_ASIO_HAS_BOOST_CHRONO | |
#define BOOST_CHRONO_HAS_CLOCK_STEADY | |
#include <boost/asio/io_service.hpp> | |
#include <boost/asio/write.hpp> | |
#include <boost/asio/steady_timer.hpp> | |
#include <boost/asio/ssl.hpp> | |
#include <boost/bind.hpp> | |
#include <boost/chrono/include.hpp> | |
#include <boost/asio/buffer.hpp> | |
#include <boost/asio/ip/tcp.hpp> | |
#include <boost/array.hpp> | |
#include <boost/> | |
#include <thread> | |
using namespace boost::asio; | |
using namespace boost::asio::ip; | |
io_service ioService; | |
tcp::resolver resolver{ioService}; | |
tcp::socket tcpSocket{ioService}; | |
std::array<char, 4096> bufBytes; | |
void readHandler(const boost::system::error_code &errorCode, std::size_t transferredByte) { | |
if (!errorCode) { | |
std::cout.write(bufBytes.data(), transferredByte); | |
tcpSocket.async_read_some(buffer(bufBytes), readHandler); | |
} | |
} | |
void connectHandler(const boost::system::error_code &errorCode) { | |
if (!errorCode) { | |
std::stringstream getRequest; | |
getRequest << "GET / HTTP/1.1\r\n"; | |
getRequest << "Host: 2ch.hk\r\n"; | |
getRequest << "Connection: keep-alive\r\n"; | |
getRequest << "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36\r\n"; | |
getRequest << "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n"; | |
getRequest << "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4\r\n"; | |
getRequest << "\r\n"; | |
write(tcpSocket, buffer(getRequest.str())); | |
tcpSocket.async_read_some(buffer(bufBytes), readHandler); | |
} | |
} | |
void resolverHandler(const boost::system::error_code &errorCode, tcp::resolver::iterator iterator) { | |
if (!errorCode) { | |
tcpSocket.async_connect(*iterator, connectHandler); | |
} | |
} | |
int main() { | |
tcp::resolver::query q{"2ch.hk", "80"}; | |
resolver.async_resolve(q, resolverHandler); | |
ioService.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment