3

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
QCoder
  • 79
  • 1
  • 6
  • bidirectional functionality: Send and Receive simultaneously not Request-Response like HTTP Protocol – QCoder Jun 28 '15 at 11:43

1 Answers1

4

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Your answer is correct, but is there any solution to make wininet behave like winsock. – QCoder Jun 29 '15 at 13:08
  • Behavior like it in what way exactly? Please be more specific. – Remy Lebeau Jun 29 '15 at 17:44
  • In winsock mode, I am free to call recv() and send() every where I want, but in WinInet I must have response after request and server could not request to client ( connection-back). – QCoder Jul 04 '15 at 05:41
  • 1
    @QCoder: I still do not understand what you are trying to ask for. But Winsock operates at a lower level than WinInet does. Winsock operates at the TCP layer, which is why it can send/recv raw data however you want. WinInet operates at protocol layers above TCP, which is why it is based on requests/responses. You can use `InternetReadFile/Ex()` and `InternetWriteFile()` to read/write *certain portions* of raw data related to those protocols, but you do not have the same level of control in WinInet that you have in Winsock. – Remy Lebeau Jul 04 '15 at 16:40