views:

864

answers:

4

Hi,

I am trying to use Tor-Server as a proxy in HttpWebRequest, my code looks like this:

HttpWebRequest request;
HttpWebResponse response;

request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Proxy = new WebProxy("127.0.0.1:9051");

response = (HttpWebResponse)request.GetResponse();
response.Close();

it works perfect with "normal" proxies but with Tor I am getting Exceptions while calling GetResponse() with Status = ServerProtocolViolation. The message is (in German...): Message = "Der Server hat eine Protokollverletzung ausgeführt.. Section=ResponseStatusLine"

hope anyone has an idea how to fix that. I would be grateful.

Greetings

L.

+5  A: 

Tor is not an HTTP proxy. It's a SOCKS proxy. You can use an HTTP proxy that supports forwarding on SOCKS (like Privoxy) and connect to that via code instead.

Mehrdad Afshari
argh... right. so can I use it *somehow* to make a request?
Lay
Lay: nothing is built in .NET to forward HTTP stuff via a SOCKS proxy.
Mehrdad Afshari
A: 

Yes like the other poster said, a socks client is needed. Some libraries are Starksoft Proxy, ProxySocket and ComponentSpace Socks Proxy. sockscap is a tool that intercepts and reroutes winsock calls, and privoxy is a local proxy that can tunnel your requests over socks. A couple different solutions.

jspcal
+3  A: 

If you have privoxy installed (default if you used vidalia or many other tor packages) you can do

request.Proxy = new WebProxy("127.0.0.1:8118"); // default privoxy port

Which will enable you to make requests using tor

Chris T
A: 

This Ultimate Netkit can be used for that purpose.

Mark Attwood