c++boost-asiohttp-proxy

How to pass proxy server's username and password in boost::asio::resolver::query


I am trying to establish connection to authenticated proxy. I am trying to achieve the Cpp's alternative for the following command in curl.

curl google.com --proxy http://username:password@xx.xxx.xxx.xx:xxxx

Is there any way to get connected to authenticated proxy server at least using boost::asio.

Following code is used in cpp to try connecting to proxy server.

boost::asio::ip::tcp::resolver::query query(remoteServer, port, boost::asio::ip::tcp::resolver::query::numeric_service);

I tried following - but all failed to connect to host with error - Host not found (authartive).

`#1 - boost::asio::ip::tcp::resolver::query query(xx.xxx.xxx.xx,
3128, boost::asio::ip::tcp::resolver::query::numeric_service);

#2 - boost::asio::ip::tcp::resolver::query query("http://username:password@xx.xxx.xxx.xx",
3128, boost::asio::ip::tcp::resolver::query::numeric_service);

#3 - boost::asio::ip::tcp::resolver::query query("username:password@http://xx.xxx.xxx.xx",
3128, boost::asio::ip::tcp::resolver::query::numeric_service);

#4 - boost::asio::ip::tcp::resolver::query query("username:password@http://xx.xxx.xxx.xx/google.com",
3128, boost::asio::ip::tcp::resolver::query::numeric_service);

#5 - boost::asio::ip::tcp::resolver::query query("username:password@http://xx.xxx.xxx.xx:3128/google.com",
88, boost::asio::ip::tcp::resolver::query::numeric_service); `


Solution

  • Name resolution never uses the proxy.

    You resolve the (qualified hostname) of the proxy server, before connecting. Then when you connected you send the destination address to the proxy server.

    The proxy server does the DNS lookup.

    The strings you display in the question are URI's, and only used by convention by programs to do the above steps with.

    Asio does not come with proxy support builtin. You have to decide on what type of proxy server you want (HTTP, SOCKS4, SOCKS5) and select a suitable client

    There's a socks4 sample in the Asio library distribution (asio/example/cpp{03,11}/socks4).

    I've written simple clients for SOCKS4, SOCKS5 before on this site:

    For HTTP proxies: