Winsock use system proxy settings

依然范特西╮ 提交于 2021-01-27 14:20:32

问题


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 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.



来源:https://stackoverflow.com/questions/31099354/winsock-use-system-proxy-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!