【发布时间】:2019-11-28 13:48:27
【问题描述】:
最近我想从洋葱网站获取 .json 内容 (例如http://takedownmi4lfjhv.onion/root.json,这是一个现有的链接)
所以我安装了 C# 库 DotNetTor (Nuget package is here)
我复制并粘贴了 DotNetTor QuickStart Example Project 示例代码,并在我的 C# 项目中运行它。
var requestUri = "http://icanhazip.com/";
// 1. Get real IP
using (var httpClient = new HttpClient())
{
var message = httpClient.GetAsync(requestUri).Result;
var content = message.Content.ReadAsStringAsync().Result;
Console.WriteLine($"Your real IP: \t\t{content}");
}
// 2. Get TOR IP
using (var httpClient = new HttpClient(new SocksPortHandler("127.0.0.1", socksPort: 9050)))
{
var message = httpClient.GetAsync(requestUri).Result; // GOT ERROR HERE // GOT ERROR HERE
var content = message.Content.ReadAsStringAsync().Result;
Console.WriteLine($"Your TOR IP: \t\t{content}");
// 3. Change TOR IP
var controlPortClient = new DotNetTor.ControlPort.Client("127.0.0.1", controlPort: 9051, password: "ILoveBitcoin21");
controlPortClient.ChangeCircuitAsync().Wait();
// 4. Get changed TOR IP
message = httpClient.GetAsync(requestUri).Result;
content = message.Content.ReadAsStringAsync().Result;
Console.WriteLine($"Your other TOR IP: \t{content}");
}
但是,在我标记// GOT ERROR HERE的那一行,却弹出了一个错误
System.AggregateException
Inner Exception 1:
TorException: Failed to send the request
Inner Exception 2:
SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:9050
为什么发送请求失败?如何解决?
【问题讨论】:
标签: c# .net http httprequest tor