Dgameman1
Dgameman1

Reputation: 378

WebProxy URI is not valid

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

Upvotes: 0

Views: 1198

Answers (2)

Umut D.
Umut D.

Reputation: 1846

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

Upvotes: 1

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33391

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

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

Upvotes: 1

Related Questions