代码之家  ›  专栏  ›  技术社区  ›  MicMit

Windows 7虚拟机.Net Webclient System.Net.WebException:远程服务器返回错误:(407)需要代理身份验证

  •  1
  • MicMit  · 技术社区  · 14 年前

    可能导致什么 System.Net.WebException:远程服务器返回错误:(407)需要代理身份验证。Windows网络客户端

            WebClient client = new WebClient();
            client.DownloadFile(Uri, "test.html"); // fails
            string html = client.DownloadString(Uri); // fails 
    

    我看不到任何代理设置在Internet Explorer和同一个框Com自动化驱动的Visual Foxpro工程没有任何代理。

    oxmlhttp = createobject("microsoft.xmlhttp")
    oxmlhttp.open('GET', lcURL, .t.)
    oxmlhttp.send()
    

    1 回复  |  直到 14 年前
        1
  •  1
  •   MicMit    14 年前

    不确定它有多强大,但在调用下载之前添加这些行解决了我的问题。

    IWebProxy theProxy = client.Proxy;
    if (theProxy != null)
    {
        theProxy.Credentials = CredentialCache.DefaultCredentials;
    }