HttpClientHandler Proxy Unsupported

Sergey Stadniichuk 1 Reputation point
2022-07-03T14:26:48.343+00:00

In the MacOS, Proxy member in HttpClientHandler throw exception "Operation is not supported on this platform."
In code is marked
[UnsupportedOSPlatform("browser")]
What mean is "browser"? I think it must by "maccatalist"?
Is there any way to use a proxy on MacOS in HttpClient?

Developer technologies .NET .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-07-06T09:10:11.517+00:00

    Hello,

    The NSUrlSessionHandler is an HTTP client handler that delegates its work to Apple’s built-in NSUrlSession.

    Referring to the underlying NSUrlSessionHandler wrapper at NSUrlSessionHandler.cs, you could find the following code snippet:

       // We dont support any custom proxies, and don't let anybody wonder why their proxy isn't  
       // being used if they try to assign one (in any case we also return false from 'SupportsProxy').  
       [UnsupportedOSPlatform ("ios")]  
       [UnsupportedOSPlatform ("maccatalyst")]  
       [UnsupportedOSPlatform ("tvos")]  
       [UnsupportedOSPlatform ("macos")]  
       public IWebProxy? Proxy {  
       get => null;  
       set => throw new PlatformNotSupportedException ();  
       }  
    

    Therefore, we could know that HttpClientHandler doesn't support custom proxies in MacCatalyst.

    There is a pull request in progress to implement this for .Net 7. You could follow this issue: .NET Implement NSUrlSessionHandler members that throw PlatformNotSupportedException #14632.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


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.