Search code examples
c#proxyhttpwebrequestresponsetor

Trouble in Tor with C#


I've looked around links related. I can't find any. Help me, please. Here's my code.(VS2010)

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://whatismyipaddress.com/");
        request.Proxy = new WebProxy("127.0.0.1:9150");
        request.KeepAlive = false;

        try
        {
            using (var response = request.GetResponse())
            {
                using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
                {
                    string temp = reader.ReadToEnd();
                    MessageBox.Show(temp);
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

That brings error message like this. (501) Not implemented.

And Tor says.

Socks version 71 not recognized.(Tor is not a http proxy)

What's wrong?Someone help me.


Solution

  • Unfortunately after some digging TOR is not a HTTP Proxy. It's a SOCKS proxy, you can use something like Privoxy that allows sock forwarding.

    using Tor as Proxy

    How to use Privoxy with TOR: http://www.privoxy.org/faq/misc.html#TOR