The remote server returned an error: (407) Proxy Authentication Required

前端 未结 7 2101
轻奢々
轻奢々 2020-12-04 16:34

I\'m getting this error when I call a web service:

\"The remote server returned an error: (407) Proxy Authentication Required\".

I get the general idea and I

相关标签:
7条回答
  • 2020-12-04 17:01

    Just add this to config

    <system.net>
        <defaultProxy useDefaultCredentials="true" >
        </defaultProxy>
    </system.net>
    
    0 讨论(0)
  • 2020-12-04 17:04

    In following code, we don't need to hard code the credentials.

    service.Proxy = WebRequest.DefaultWebProxy;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials; ;
    service.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    0 讨论(0)
  • 2020-12-04 17:13

    Probably the machine or web.config in prod has the settings in the configuration; you probably won't need the proxy tag.

    <system.net>
        <defaultProxy useDefaultCredentials="true" >
            <proxy usesystemdefault="False"
                   proxyaddress="http://<ProxyLocation>:<port>"
                   bypassonlocal="True"
                   autoDetect="False" />
        </defaultProxy>
    </system.net>
    
    0 讨论(0)
  • 2020-12-04 17:13

    Thought of writing this answer as nothing worked from above & you don't want to specify proxy location.

    If you're using httpClient then consider this.

    HttpClientHandler handler = new HttpClientHandler();
    
    IWebProxy proxy = WebRequest.GetSystemWebProxy();
    proxy.Credentials = CredentialCache.DefaultCredentials;
    handler.Proxy = proxy;
    
    var client = new HttpClient(handler);
    // your next steps...
    

    And if you're using HttpWebRequest:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri + _endpoint);
    
    IWebProxy proxy = WebRequest.GetSystemWebProxy();
    proxy.Credentials = CredentialCache.DefaultCredentials;
    request.Proxy = proxy;
    

    Kind referencce: https://medium.com/@siriphonnot/the-remote-server-returned-an-error-407-proxy-authentication-required-86ae489e401b

    0 讨论(0)
  • 2020-12-04 17:14

    Check with your firewall expert. They open the firewall for PROD servers so there is no need to use the Proxy.

    Thanks your tip helped me solve my problem:

    Had to to set the Credentials in two locations to get past the 407 error:

    HttpWebRequest webRequest = WebRequest.Create(uirTradeStream) as HttpWebRequest;
    webRequest.Proxy = WebRequest.DefaultWebProxy;
    webRequest.Credentials = new NetworkCredential("user", "password", "domain");
    webRequest.Proxy.Credentials = new NetworkCredential("user", "password", "domain");
    

    and voila!

    0 讨论(0)
  • 2020-12-04 17:14
    HttpWebRequest webRequest = WebRequest.Create(uirTradeStream) as HttpWebRequest;
    
    webRequest.Proxy = WebRequest.DefaultWebProxy;
    
    webRequest.Credentials = new NetworkCredential("user", "password");
    
    webRequest.Proxy.Credentials = new NetworkCredential("user", "password");
    

    It is successful.

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