【问题标题】:No connection could be made because the target machine actively refused it 127.0.0.1:8118无法建立连接,因为目标机器主动拒绝它 127.0.0.1:8118
【发布时间】: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


    【解决方案1】:

    只需下载 Privoxy here

    通过 privoxy 运行 tor 的原因是因为 c# 不适用于 socks 代理。而tor是socks代理,所以需要通过tor运行的html代理运行

    【讨论】:

      【解决方案2】:

      Tor 默认代理端口是 8118。你必须先在这里下载 privoxy

      要链接 Privoxy 和 Tor,它们都运行在同一个系统上,你可以使用类似的东西:

          forward-socks5 / 127.0.0.1:9050 
      

      通过取消注释以上行来更改其配置以使用 tor

      c# 不使用 sock 代理,因此我们必须同时运行 Tor 和 Provoxy。现在您可以使用 tor 发送每个网络请求。

      【讨论】:

        猜你喜欢
        • 2015-04-05
        • 2012-03-30
        • 2017-06-06
        • 2012-02-04
        • 1970-01-01
        • 1970-01-01
        • 2013-12-14
        • 2018-07-12
        • 1970-01-01
        相关资源
        最近更新 更多