Winsock 使用系统代理设置 [英] Winsock use system proxy settings

查看:94
本文介绍了Winsock 使用系统代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 winsock 程序,我想通过系统代理传递我的连接.我看到一些帖子解释了如何捕获系统代理然后发送如下字符串:

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

等等.但它并不总是完全有效.另一方面,当使用 WinInet API( InternetOpen() 函数和 ... )时,它工作得很好.我需要像 WinInet 这样始终正常工作的解决方案和像 Winsocket 这样的双向功能.

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.

推荐答案

没有系统代理"这样的东西.WinInet 的代理设置只是 WinInet 的一部分,而不是 Windows 本身(Internet Explorer 使用 WinInet,因此 WinInet 配置会影响 IE,但不会影响 WinSock).

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 是用于通过基于 HTTP 的代理服务器建立隧道的连接字符串(请参阅 使用 HTTP 连接的隧道).您连接到代理,发送CONNECT命令让它连接到目标服务器,检查响应,如果成功就可以像连接一样正常与目标服务器进行双向通信直接给它.

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.

但是还有其他类型的代理,例如 SOCKS.相同的概念(连接到代理,请求连接到目标,然后正常进行),但协议与 HTTP 非常不同.

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.

使用 WinSock 进行编码时,您必须在自己的代码中手动实现各种代理协议,或者寻找第三方库为您处理.WinSock 没有内置的代理支持.而且您必须提前知道正在使用什么类型的代理,以便您可以使用正确的协议.有一些 API 可以动态检测代理设置,或者只是要求用户提供详细信息.

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.

这篇关于Winsock 使用系统代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆