How to authenticate against a proxy when using the HttpClient class?

前端 未结 2 2032
有刺的猬
有刺的猬 2020-12-02 21:25

I have a console app built on .NET 4 that uses the HttpClient library (obtained via NuGet) to retrieve data from a public API over the internet. The console app

相关标签:
2条回答
  • 2020-12-02 21:46

    I managed to solve my problem very simply through proxy configuration in app.config.

    <system.net>
        <defaultProxy enabled="true" useDefaultCredentials="true">
            <proxy usesystemdefault="True" />
        </defaultProxy>
    </system.net>
    

    http://msdn.microsoft.com/en-us/library/dkwyc043.aspx

    0 讨论(0)
  • 2020-12-02 21:58

    If you wanted to do the same programmatically you could use the following:

    WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
    

    (These objects are from the `System.Net' namespace).

    Some more info from MSDN: http://msdn.microsoft.com/en-us/library/system.net.webproxy.getdefaultproxy.aspx

    0 讨论(0)
提交回复
热议问题