WebProxy URI 无效

WebProxy URI is not valid

这是我目前拥有的代码

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); 上遇到错误 说

"The URI scheme is not valid."

不确定它期望什么样的值

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

proxy.Address = new Uri("http://96.44.147.138:6060");

一定要赞;

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/"));
}

示例编辑:Setting a global HTTP proxy in C# and .NET client classes