Winsock use system proxy settings

3.2k views Asked by At

I have a simple winsock program and I want pass my connection through system proxy. I saw some post that explain how to catch system proxy and then send string like below:

CONNECT 127.0.0.1:8080 HTTP/1.0\r\n

and so on. But it doesn't work exactly all the time. In other hand, when using WinInet API ( InternetOpen() Function and ... ) it works perfectly. I need solution like WinInet that works correctly always and bidirectional functionality like Winsocket.

1

There are 1 answers

4
Remy Lebeau On BEST ANSWER

There is no such thing as a "system proxy". WinInet's proxy settings are part of WinInet only, not Windows itself (Internet Explorer uses WinInet, so WinInet configurations affect IE, but not WinSock).

CONNECT 127.0.0.1:8080 HTTP/1.0\r\n\r\n is a connection string for establishing a tunnel through an HTTP-based proxy server (see Tunneling with HTTP CONNECT). You connect to the proxy, send the CONNECT command to have it connect to the target server, check the response, and if successful then you can carry on bidirectional communications with the target server normally as if you had connected to it directly.

But there are other kinds of proxies, such as SOCKS. Same concept (connect to proxy, request connection to target, carry on normally afterwards), but very different protocol than HTTP.

When coding with WinSock, you have to implement the various proxy protocols manually in your own code, or find a third-party library to handle it for you. WinSock has no built-in support for proxies. And you have to know ahead of time what type of proxy is being used so you can use the correct protocol. There are APIs to detect the proxy settings dynamically, or just ask the user to provide the details.