Skip to content

Support for Proxy in HttpClient in iOS #18635

Closed

Description

@rolfbjarne

From @Syed-RI on Fri, 19 May 2023 13:23:03 GMT

Description

Please provide support/implementations to enable proxy in iOS

We are currently working on some enterprise applications which will be deployed to corporate devices via their MDM systems and they will enforce proxy on these devices. I was horrified seeing this bit of warning in my .NET MAUI app

Screenshot 2023-05-19 at 14 15 50

Bit of search revealed more horrors here: #14632

May be this is bit late for our project and we will have to abstract and have platform specific, unmanaged HttpClientHandlers to support proxy in iOS devices. Is there any proposal anywhere or official workaround? Apologies, if there is any and I have somehow missed it.

CC @davidortinau @PureWeen @Redth @rolfbjarne for visibility

Public API Changes

NONE

Intended Use-Case

To support and enable proxy in IHttpClientFactory for iOS devices

Copied from original issue dotnet/maui#15179

Activity

  1. rolfbjarne commented on Aug 4, 2023

    @rolfbjarne
    MemberAuthor

    From @Eilon on Thu, 03 Aug 2023 21:03:20 GMT

    @rolfbjarne - does this seem like it should move to xamarin-macios or dotnet/runtime?

  2. added
    bug
    feature
    and removed
    bug
    on Aug 4, 2023
  3. added this to the Future milestone on Aug 4, 2023
  4. added
    dotnet
    on Aug 4, 2023
  5. Syed-RI commented on Aug 4, 2023

    @Syed-RI

    Glad to see that the issue is getting a bit of attention! ❤️

  6. modified the milestones: Future, .NET 9 on Sep 12, 2023
  7. M4ttsson commented on Sep 19, 2023

    @M4ttsson

    Hi, just ran into this problem when migrating away from an old Xamarin project.

    Since Proxy settings is not supported (anymore?), what would be the default behavior on iOS if not setting the proxy by code? Would the app respect any proxy from the system settings on the device, or try to go directly bypassing the proxy?

    If bypassing, is there any workarounds to this since waiting until .NET 9 is not an option due to Xamarin EOL..

    Thanks

  8. rolfbjarne commented on Sep 19, 2023

    @rolfbjarne
    MemberAuthor

    Hi, just ran into this problem when migrating away from an old Xamarin project.

    Since Proxy settings is not supported (anymore?), what would be the default behavior on iOS if not setting the proxy by code? Would the app respect any proxy from the system settings on the device, or try to go directly bypassing the proxy?

    If bypassing, is there any workarounds to this since waiting until .NET 9 is not an option due to Xamarin EOL..

    Thanks

    Yes, it will use the system proxy settings.

    You might also be able to use the .NET http handler instead of the native one, by setting this in your csproj:

    <PropertyGroup>
        <UseNativeHttpHandler>false</UseNativeHttpHandler>
    </PropertyGroup>

    There are a few downsides:

  9. Axemasta commented on Jan 5, 2024

    @Axemasta

    Now maui is in a relatively stable place, will there be support for this natively without the workaround described?

    Using a proxy is important to an app I am working on and I dont want to lose the advantages of the native platform (there will be device proxies setup for example). Any idea of when this change would come into effect?

  10. rolfbjarne commented on Jan 8, 2024

    @rolfbjarne
    MemberAuthor

    @Axemasta no news yet, but we're trying to have a look at this in the .NET 9 time frame (no promises though).

  11. moved this to Technical Debt in .NET 9on Aug 27, 2024
  12. modified the milestones: .NET 9, .NET 10 on Sep 27, 2024
  13. added
    networking
    on Sep 27, 2024
  14. Pamoi commented on Mar 12, 2025

    @Pamoi

    There is a workaround by using SocketsHttpHandler which is supported on iOS. For example:

    var proxy = new WebProxy("http://your-proxy-url:port") // Replace with your proxy
    
    var handler = new SocketsHttpHandler
    {
        UseProxy = true,
        Proxy = proxy,
        // Make sure to reuse TCP connections, but still refresh it every 5 minutes for DNS updates
        PooledConnectionLifetime = TimeSpan.FromMinutes(5)
    };
    
    var client = new HttpClient(handler);
    
  15. modified the milestones: .NET 10, .NET 11 on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetfeaturenetworking

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions