【发布时间】:2014-04-22 12:32:10
【问题描述】:
尝试使用 Tor 创建 Web 请求。收到此错误 - “无法连接到远程服务器”。 Tor 默认代理 - 8118。 我已经为它找到了解决方案using Tor as Proxy,但它对我没有用。
代码-
Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Users\king\Downloads\Tor Browser\App\tor.exe", "ControlPort 9151 CircuitBuildTimeout 10");
p.Start();
Thread.Sleep(5000);
Regex regex = new Regex("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", RegexOptions.Multiline);
do
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://whatismyipaddress.com/");
request.Headers.Add("Cache-Control", "max-age=0");
request.Proxy = new WebProxy("127.0.0.1:8118");
request.KeepAlive = false;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
{
string contenu = reader.ReadToEnd();
Console.WriteLine(regex.Match(contenu).Groups[0].Value);
}
}
Console.Write("en attente : continuez ?");
string line = Console.ReadLine();
if (line != "y")
break;
}
while (true);
p.Kill();
Console.ReadLine();
任何想法在上面的代码中做错了什么。 谢谢
【问题讨论】:
标签: proxy httpwebrequest webrequest tor