Adding credential for connection through proxy using boost.asio

30 Views Asked by At

The code that I used to create a client in order to doing a connection through proxy is:

    tcp::resolver::query query  (protocol, target_URL, port_str);

    tcp::resolver::query query_proxy  (protocol, proxy_server_ip, proxy_port_str);

    auto endpoints = resolver.resolve(query_proxy);
    boost::asio::connect(ssl_stream.lowest_layer(), endpoints);

    ssl_stream.set_verify_depth(1);

    bool use_ssl = true;
    ssl_iostream_device ssl_device(ssl_stream, use_ssl);
    bool result = ssl_device.handshake(ssl::stream_base::handshake_type::client);
    if (result)
        std::cout<<"Handshake is make it"<<std::endl;


    const std::string target = "https://" + target_URL ;
    std::cout<<"Page target "<<target<<std::endl;
    int version = 11;

    http::request<http::string_body> req{ http::verb::get, target, version };
    req.set(http::field::host, target_URL);
    req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);

    http::write(ssl_stream, req);

    beast::flat_buffer buffer;
    http::response<http::dynamic_body> res;
    http::read(ssl_stream, buffer, res);

The question is how can be added username and password for proxy.

0

There are 0 best solutions below