Xamarin Forms: [UWP] HttpClientHandler Proxy setting not work

Takeuchi Yuuki 46 Reputation points
2021-03-18T09:13:34.057+00:00

I want to access a website via a proxy from Xamarin.Forms UWP app.
I set a proxy for HttpClientHandler, but it goes directly to the website without going through the proxy.

Code - some button clicked code behind event.

    private async void Button_Clicked(object sender, EventArgs e)
    {
        using (HttpClientHandler hander = new HttpClientHandler()
        {
            Proxy = new System.Net.WebProxy
            {
                Address = new Uri(@"http://172.20.90.87:8080"),
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential("******@gs.com", "Password1!")
            },
            UseProxy = true
        })
        {
            using (HttpClient client = new HttpClient(hander))
            {
                var res = await client.GetAsync(@"https://www.google.co.jp");
                lblMessage.Text = await res.Content.ReadAsStringAsync();
            }
        }
    }

===============

Xamarin.Forms 4.8.0.1451

Developer technologies | .NET | Xamarin
Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
    2021-03-19T05:31:13.413+00:00

    Hello, Welcome to Micorosoft Q&A,

    HttpClientHandler Proxy setting not work

    Derive from this blog proxy part.

    proxy settings are automatically obtained from Internet Explorer/Microsoft Edge settings and are used for all the HTTP calls by default. This enables apps to automatically work even if the user is connected to the internet through a proxy. Neither API provides a way to specify a custom proxy for your app.

    So we can't use a custom proxy for a single HTTP request by now. But you are welcome to ask for this feature with Windows Feed Back Hub.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.