0

I'm trying to use a proxy to access a webpage but I am getting:

URI could not be determined

Here is my code:

WebProxy proxy = new WebProxy();
proxy.Address = new Uri("myproxyaddress");
proxy.UseDefaultCredentials = true;
proxy.BypassProxyOnLocal = false;  

WebClient client = new WebClient();
client.Proxy = proxy;

string doc = client.DownloadString("http://www.google.com/");
Pang
  • 9,564
  • 146
  • 81
  • 122
  • Based on [this answer](https://stackoverflow.com/a/3675053/6741868) you could try adding `UriKind.Relative` or `UriKind.Absolute` depending on your proxy address, also recheck to make sure it is valid. – Keyur PATEL Jul 06 '17 at 01:20

1 Answers1

0

This error happens when you try creating a URI and the constructor can't determine what format to parse the URI as (Relative or Absolute).

Normally, if you are specifying a full valid URL you won't have this issue.

If for some reason you can specify the kind of URI you are trying to create (UriKind.Absolute or UriKind.Relative)

For your purposes, you will need an absolute URI, which can be created like this:

var url = new Uri("myproxyaddress", UriKind.Absolute);
proxy.Address = url;

Odds are that you might get an error calling new Uri("myproxyaddress", UriKind.Absolute) because the underlying issue is that "myproxyaddress" isn't a valid absolute URI.

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41