WebProxy URI is not valid

c# webproxy

571 просмотра

2 ответа

This is the code I currently have

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

The proxy needs credentials.

I get an error on line proxy.Address = new Uri(96.44.147.138:6060); saying

"The URI scheme is not valid."

Not sure what kind of value it's expecting

Автор: Dgameman1 Источник Размещён: 08.11.2019 11:03

Ответы (2)


1 плюс

Решение

The Uri should consist of scheme host and optiona port. So you should use

proxy.Address = new Uri("http://96.44.147.138:6060");
Автор: Hamlet Hakobyan Размещён: 20.08.2016 08:24

1 плюс

Must be like;

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

Example edit: Setting a global HTTP proxy in C# and .NET client classes

Автор: Umut D. Размещён: 20.08.2016 08:24
Вопросы из категории :
32x32