0

这是我目前拥有的代码

using (WebClient client = new WebClient()) {
    WebProxy proxy = new WebProxy();
    proxy.Address = new Uri(96.44.147.138:6060);
    proxy.Credentials = new NetworkCredential(proxyUsername.Text, proxyPassword.Text);
    proxy.UseDefaultCredentials = false;
    proxy.BypassProxyOnLocal = false;
    Console.WriteLine(client.DownloadString("http://bot.whatismyipaddress.com/"));
}

代理需要凭据。

我在网上收到一条错误proxy.Address = new Uri(96.44.147.138:6060); 消息

“URI 方案无效。”

不确定它期望什么样的价值

4

2 回答 2

1

应该由Uri方案主机和可选端口组成。所以你应该使用

proxy.Address = new Uri("http://96.44.147.138:6060");
于 2016-08-20T08:24:12.527 回答
1

必须像;

using (var client = new WebClient())
{
    var proxy = new WebProxy();

    proxy.Address = new Uri("http://96.44.147.138:6060");
    proxy.Credentials = new NetworkCredential(proxyUsername.Text, proxyPassword.Text);
    proxy.UseDefaultCredentials = false;
    proxy.BypassProxyOnLocal = false;

    Console.WriteLine(client.DownloadString("http://bot.whatismyipaddress.com/"));
}

示例编辑:在 C# 和 .NET 客户端类中设置全局 HTTP 代理

于 2016-08-20T08:24:38.253 回答