Para Para - 5 months ago 117
C# Question

Use WebClient with socks proxy

Is there any way to use a socks proxy with

? Specifically with the
method that it provides?

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 in fact I used their
implementation but they don't seem to have something similar for WebClient.

Thank you.


SOCKS is not supported directly by the WebRequest/WebResponse classes and by extension, the WebClient class (it relies on WebRequest to do its work).

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

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.

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