HttpClient and using proxy - constantly getting 407

前端 未结 3 1413
醉话见心
醉话见心 2020-11-28 23:00

Here is the code:

 HttpClient client = null;
 HttpClientHandler httpClientHandler = new HttpClientHandler()
 {
    Proxy = new WebProxy(string.Format(\"{0}:{         


        
3条回答
  •  难免孤独
    2020-11-28 23:30

    I found some useful information about this here from social.msdn.microsoft.com. From the replies, tests I made and research into the System.Net.WebProxy Class you need to pass the proxy credentials into the proxy object, not the HttpClientHandler.

    {
        Proxy = new WebProxy(string.Format("{0}:{1}", proxyServerSettings.Address, 
        proxyServerSettings.Port),false),
        PreAuthenticate = true,
        UseDefaultCredentials = false,
        Credentials = new System.Net.NetworkCredential(proxyServerSettings.UserName, 
                        proxyServerSettings.Password),
    };
    

    This actually is meant to authenticate the connection to the proxy, not the HttpClientHandler.

提交回复
热议问题