如果不通过代理,下面的代码可以取到HttpWebResponse。认证方式为:NTLM。
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.Timeout = 60000;
httpWebRequest.KeepAlive = true;
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();但如果通过代理,运行下面这段代码后,依然有异常发生,信息为“远程服务器返回错误: (407) 需要代理身份验证。”,我看了一下,WebProxy.GetDefaultProxy();返回的代理服务器是正确的。httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.Timeout = 60000;
httpWebRequest.KeepAlive = true;
httpWebRequest.Proxy = WebProxy.GetDefaultProxy();
httpWebRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

解决方案 »

  1.   

    谁能告诉我,如果使用代理服务器得到httpWebResponse,认证方式是NTLM.
      

  2.   

    http://www.microsoft.com/china/msdn/archives/library/techart/pdc_websvc.ASP
      

  3.   

    http://www.xfbbs.com/Book/others/jishidaquan/17/40389.html
      

  4.   

    try it,我的一段代码:
    WebProxy proxy = WebProxy.GetDefaultProxy();
    proxy.Credentials = new NetworkCredential(ClientInfo.ProxyUsername,ClientInfo.ProxyPassword,ClientInfo.ProxyDomain);
    httpReq.Proxy = proxy;