HttpWebRequest 的 Socks 代理

发布于 2024-09-26 11:42:26 字数 533 浏览 1 评论 0原文

根据我的研究,在尝试解决这个问题时,它事实证明 .Net WebProxy 类不支持 Socks 代理 - 有点烦人。我似乎也找不到任何代码或信息来解释如何通过可以轻松与 HttpWebRequest (确切地说是 Proxy 属性)一起使用的类来实现 Socks 4/5 支持。

我通过谷歌找到了关于如何做到这一点的有限信息。 一个建议涉及更改 Internet Explorer 代理设置 - 我不想这样做。

有谁知道有什么可以完成这项工作或有任何建议吗?任何帮助将不胜感激。

According to my research whilst trying to solve this problem, it turns out that the .Net WebProxy class does not support Socks proxies - a tad annoying. I also can't seem to find any code or information which explains how to implement Socks 4/5 support via a class which can easily be used with HttpWebRequest (the Proxy property, to be exact).

I've found limited information via google on how I could do this. One suggestion involves changing internet explorer proxy settings - something I'd rather not do.

Does anyone know of anything which could do the job or have any suggestions? Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╭⌒浅淡时光〆 2024-10-03 11:42:26

我尝试了许多声称支持 Socks4/5 的 .Net 库,但发现其中许多库不起作用,或者在尝试连接到我知道正在运行的代理时会出错。

我最终使用了 Chilkat Software 的 Sock/SSL 组件,它似乎对我来说效果很好即使我确实必须手动构造 HTTP 请求,而不是像我希望的那样使用 HttpWebRequest。

  • 更新说明:Chilkat.Http(类似于 HttpWebRequest 类)本质上支持 SOCKS 代理。因此,不要像我一样花时间尝试编写自己的 HTTP 请求;只需使用 Chilkat.Http.SocksHostname、Chilkat.Http.SocksPort 和 Chilkat.Http.SocksVersion 属性即可。

I tried numerous .Net libraries which claimed to support Socks4/5 but found many of them just did not work or would error trying to connect to proxies I knew were functioning.

I've ended up using Chilkat Software's Sock/SSL component which seems to work well for me even if I do have to manually construct the HTTP requests instead of using HttpWebRequest as I would have liked.

  • Update note: Chilkat.Http (similar to the HttpWebRequest class) does inherently have support for SOCKS proxies. So don't spend time trying to code your own HTTP requests as I did; just use the Chilkat.Http.SocksHostname, Chilkat.Http.SocksPort and Chilkat.Http.SocksVersion properties.
那小子欠揍 2024-10-03 11:42:26

更改 IE 的代理设置根本不会帮助您——另一位发帖者只是观察到它适用于 IE。由于 .NET Framework 不支持 SOCKS,因此您必须编写自己的 CERN-Proxy 到 SOCKS-Proxy 转换器,以便 .NET 与 CERN 代理(它支持的类型)对话,并且您的代码将其转换为SOCKS 代理调用。

FWIW,这是我目前希望添加到 FiddlerCore (www.fiddler2.com/core) 的内容,因为我已经拥有几乎所有代码。我唯一真正需要的是一个用于测试的 SOCKSv4a 代理。

Changing IE's proxy settings won't help you at all-- the other poster was just observing that it works for IE. Because the .NET Framework doesn't support SOCKS, you'd have to write your own CERN-Proxy to SOCKS-Proxy converter, such that .NET talks to the CERN proxy (the type it supports) and your code converts that to a SOCKS proxy call.

FWIW, this is something I'm presently looking to add to FiddlerCore (www.fiddler2.com/core) because I already have almost all of the code. The only thing I really need is a SOCKSv4a proxy to test against.

聚集的泪 2024-10-03 11:42:26

从 .NET 6 开始,socks 代理可以在本机上与 HttpClient 一起使用。请参阅 GitHub 上的问题。

Since .NET 6, socks proxies can be used natively with HttpClient. See this issue on GitHub.

渡你暖光 2024-10-03 11:42:26

使用 Privoxy 或相同的方法为您的袜子创建 http 代理网关。

将其添加到主配置中以链接 Privoxy 和袜子:

forward-socks5 / proxy_host:port 。

以及类似的内容以启用对本地网络的直接访问:

forward 192.168.*.*/ 。
向前 10.*.*.*/ 。
转发 127.*.*.*/ .

Use Privoxy or same to create http proxy gateway to your socks.

Add this to main config to chain Privoxy and socks:

forward-socks5 / proxy_host:port .

And something like that to enable direct access to your local network:

forward 192.168.*.*/ .
forward 10.*.*.*/ .
forward 127.*.*.*/ .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文