I need a simple HTTP GET request to work with a custom proxy. I'm not talking about getting the Windows default proxy settings here but custom ones.
In a Xamarin Android app, the following code does work:
string myProxy = "100.100.100.100:7777";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://my_uri"));
request.Proxy = new WebProxy(myProxy, false);`
In an Windows Universal App project, the class WebProxy
isn't implemented. So I followed this answer to create a custom implementation: Location of IWebProxy implementation for .NET Core
My code is now:
public class MyProxy : IWebProxy
{
public Uri GetProxy(Uri destination)
{
return new Uri("http://100.100.100.100:7777");
}
public bool IsBypassed(Uri host)
{
return false;
}
public ICredentials Credentials { get; set; }
}
and then...
request.Proxy = new MyProxy();
It doesn't work though. In fact, if I set a breakpoint inside of GetProxy
, it doesn't even get hit.
It just ignores the Proxy setting and uses the Windows 10 default settings.