【问题标题】:C# Using a proxy for WebClientC# 为 WebClient 使用代理
【发布时间】:2016-08-10 01:53:08
【问题描述】:

这是我现在的代码

using (WebClient client = new WebClient()) 
{
    Console.WriteLine(client.DownloadString("http://bot.whatismyipaddress.com/"));
}

现在,我想为代理添加 2 个选项。

  1. 标准 IP:Proxy 的选项
  2. 带有身份验证的选项。

我似乎无法弄清楚如何将它与上面的代码联系起来

【问题讨论】:

    标签: c# proxy webclient


    【解决方案1】:
        using (WebClient client = new WebClient()) {
            client.Proxy = new WebProxy("31.4.5.26", 8080); // proxy's host,port
            client.Proxy.Credentials = new NetworkCredential("proxyuser", "proxypassword");
            Console.WriteLine(client.DownloadString("http://bot.whatismyipaddress.com/"));
        }
    

    对我来说很好用!

    【讨论】:

      猜你喜欢
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 2022-12-16
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      相关资源
      最近更新 更多