dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.92k stars 525 forks source link

HttpClientHandler not picking up PAC proxy on Android #6795

Closed Safeer-Ahmad closed 4 months ago

Safeer-Ahmad commented 2 years ago

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

Xamarin.Android 11.2.2.1

Description

I've specified proxy on android using PAC file and have set HTTP client implementation to AndroidClientHandler and my expectation is when I send an HTTP request using HttpClient in my Forms project, it should be able to pick up the proxy settings and send the request accordingly. However, its not working and trying to hit the url directly than going through proxy.

I've looked at below issue and seems like there has been a fix released to use proxy if present.

https://github.com/xamarin/xamarin-android/issues/3058[](url)

Steps to Reproduce

Did you find any workaround?

No response

Relevant log output

No response

Safeer-Ahmad commented 2 years ago

Any update on this, please?

Safeer-Ahmad commented 2 years ago

here is a sample code I'm using but isn't picking up PAC proxy..

var handler = new HttpClientHandler(); handler.Proxy = WebRequest.GetSystemWebProxy(); handler.UseProxy = true; httpClient = new HttpClient(handler) { BaseAddress = new Uri("https://api.agify.io/") };

grendello commented 2 years ago

Since it's all BCL, it's likely a Mono issue, @steveisok can you assign someone to this please? Thanks!

Safeer-Ahmad commented 2 years ago

This is getting frustrating now, it's been over a week, and still no response. Please update me on this issue ASAP as this is a blocker for us atm. Thanks

steveisok commented 2 years ago

@Safeer-Ahmad What device(s) are you using and what api level are you targeting?

Safeer-Ahmad commented 2 years ago

We are targeting Android 9 (pie) and running it on Samsung mobile, Datalogic HHT and Zebra TC 51 running android 9+

Safeer-Ahmad commented 2 years ago

` HttpClientHandler handler = new HttpClientHandler { UseProxy = true, Proxy = WebRequest.DefaultWebProxy };

                var client = new HttpClient(handler);

`

This worked for me, thanks all.

jpobst commented 4 months ago

With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.

If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android or greater. Please include a link to this issue for context.