Lay*_*Lay 33 c# proxy httpwebrequest tor
我正在尝试使用Tor-Server作为代理HttpWebRequest,我的代码如下所示:
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();
Run Code Online (Sandbox Code Playgroud)
它与"正常"代理完美配合,但使用Tor我在调用时遇到异常
GetResponse() with Status = ServerProtocolViolation. The message is (in German...):Message = "Der Server hat eine Protokollverletzung ausgeführt.. Section=ResponseStatusLine"
Chr*_*ini 34
如果您已安装并运行了privoxy,则可以执行此操作
request.Proxy = new WebProxy("127.0.0.1:8118"); // default privoxy port
Run Code Online (Sandbox Code Playgroud)
这将使您能够使用tor发出请求
Meh*_*ari 23
Tor 不是 HTTP代理.这是一个SOCKS代理.您可以使用支持SOCKS转发的HTTP代理(如Privoxy)并通过代码连接到该代理.
是的,就像另一张海报所说,需要袜子客户.一些库是Starksoft Proxy,ProxySocket和ComponentSpace Socks Proxy.sockscap是一个拦截和重新路由winsock调用的工具,而privoxy是一个本地代理,可以通过socks隧道传递你的请求.几种不同的解决方案.
使用库“SocksWebProxy”。您可以将它与 WebClient 和 WebRequest 一起使用(只需为 *.Proxy 属性分配一个新的 SocksWebProxy)。无需 Privoxy 或类似服务将 http 流量转换为 Tor。
https://github.com/Ogglas/SocksWebProxy
我还通过启用控制端口对其进行了一些扩展。以下是如何在不启动 Tor 浏览器捆绑包的情况下让 Tor 在后台运行并控制 Tor,我们可以使用 Telnet 或通过 Socket 以编程方式发送命令。
Socket server = null;
//Authenticate using control password
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151);
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Connect(endPoint);
server.Send(Encoding.ASCII.GetBytes("AUTHENTICATE \"your_password\"" + Environment.NewLine));
byte[] data = new byte[1024];
int receivedDataLength = server.Receive(data);
string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
//Request a new Identity
server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine));
data = new byte[1024];
receivedDataLength = server.Receive(data);
stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
if (!stringData.Contains("250"))
{
Console.WriteLine("Unable to signal new user to server.");
server.Shutdown(SocketShutdown.Both);
server.Close();
}
else
{
Console.WriteLine("SIGNAL NEWNYM sent successfully");
}
Run Code Online (Sandbox Code Playgroud)
配置 Tor 的步骤:
tor.exe --hash-password “your_password_without_hyphens” | morehashedControlPassword 16:3B7DA467B1C0D550602211995AE8D9352BF942AB04110B2552324B2507。如果您接受密码为“password”,则可以复制上面的字符串。tor.exe -f .\torrc-defaultstelnet localhost 9151autenticate “your_password_with_hyphens”” 如果一切顺利,您应该看到“250 OK”。SIGNAL NEWNYM”,你会得到一个新的路由,也就是新的IP。如果一切顺利,您应该会看到“250 OK”。setevents circ”(电路事件)以启用控制台输出getinfo circuit-status”查看当前电路