将WebClient与袜子代理一起使用 [英] Use WebClient with socks proxy
问题描述
是否可以在 WebClient
中使用袜子代理?特别是它提供的 DownloadString
方法?
Is there any way to use a socks proxy with WebClient
? Specifically with the DownloadString
method that it provides?
我不想使用任何第三方东西,例如privoxy,freecap,也不能使用Chilkat的商业库。我尝试使用 http://www.mentalis.org/ 中的内容,实际上我使用了它们的 WebRequest
实现,但WebClient似乎没有类似的东西。
I don't want to use any third party stuff like privoxy, freecap whatever and I can't use commercial libraries like those from Chilkat. I tried using stuff from http://www.mentalis.org/ in fact I used their WebRequest
implementation but they don't seem to have something similar for WebClient.
推荐答案
< WebRequest
/ WebResponse
类,通过扩展, WebClient 类(它依靠 WebRequest
来完成其工作)。
SOCKS is not supported directly by the WebRequest
/WebResponse
classes and by extension, the WebClient class (it relies on WebRequest
to do its work).
它实际上不能,因为它在传输层(TCP / IP)上工作,而不是通过简单的重定向到转发HTTP请求的服务器(这是 WebRequest
/ WebResponse
类起作用)。
It really can't, as it works on the transport layer (TCP/IP) and not through a simple redirect to a server that forwards HTTP requests (which is the level that the WebRequest
/WebResponse
classes work on).
您可以创建 WebRequest
/ WebResponse
(使用 ProxySocket
来处理低级别的握手,然后),然后创建一个专门的 WebClient
类会覆盖 GetWebRequest
和 GetWebResponse
方法。
You can create a specialized derivation of WebRequest
/WebResponse
(that uses ProxySocket
to handle the low-level handshaking and then) and then create a specialized WebClient
class which overrides the GetWebRequest
and GetWebResponse
methods.
一旦您用该类替换了 WebClient
实例,它应该可以正常工作(不过,在每种情况下都可能需要设置代理)。
Once you have that class substituted for your WebClient
instances, it should work as normal (you might have to set up the proxy in each case where you use it though).
这篇关于将WebClient与袜子代理一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!