Proxy for HttpUtils and HttpClient

We’re using this one:

var response = $"{year}/{countryCode}".GetJsonFromUrl();

And it won’t go through proxy. Validated that the proxy works on the machine (url is open etc), it’s even set as system default proxy.

None of the suggestions here seems to work:

For example, the

url.GetJsonFromUrl(requestFilter: req.Proxy = new WebProxy("http://webproxy:80/"));

which should probably be

url.GetJsonFromUrl(requestFilter: req => req.Proxy = new WebProxy("http://webproxy:80/"));

fails on the “req” does not have the Proxy attribute.

The web.config thing makes no difference.

We have also tried this, in Startup.cs AppHost’s Configure():


and the suggested

WebProxy proxyObject = new WebProxy("http://xxxxxxxx:8888");
GlobalProxySelection.Select = proxyObject;

None seem to work. Any suggestions?

From v6 the HTTP Utils extension methods utilize HttpClient which can’t configure a Proxy per request, but you can configure all methods to use a custom HttpClientHandler by configuring HttpUtils.HttpClientHandlerFactory, e.g:

HttpUtils.HttpClientHandlerFactory = () => new() {
    UseDefaultCredentials = true,
    AutomaticDecompression = DecompressionMethods.Brotli 
        | DecompressionMethods.Deflate | DecompressionMethods.GZip,
    Proxy = new WebProxy(proxyUrl)
1 Like

Yes this worked. Thanks!

Don’t know why system proxy isn’t working though, but that’s not SS specific. E.g.
Proxy = WebRequest.GetSystemWebProxy() did not work, but new WebProxy(url here) did work.

(and of course System Proxy is set).

Microsoft’s docs suggests it only applies to instances of WebReqeust.