如果不通过代理,下面的代码可以取到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();
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();
WebProxy proxy = WebProxy.GetDefaultProxy();
proxy.Credentials = new NetworkCredential(ClientInfo.ProxyUsername,ClientInfo.ProxyPassword,ClientInfo.ProxyDomain);
httpReq.Proxy = proxy;