HTTPS - 需要407代理身份验证

时间:2014-09-26 18:27:43

标签: .net web-services https proxy httpwebrequest

我正在使用以下代码拨打我的合作伙伴网络服务。此代码工作正常,能够从DEV环境中的伙伴处提取xml消息。但是,当我将此代码移动到INTEGRATION Environment时,它会出现错误需要407代理身份验证。当我联系我的网络团队时,他们说,我的代码正试图通过代理服务器进行调用。

但是,根据下面的代码,我没有配置通过代理服务器调用合作伙伴服务的任何东西。你能告诉我,我能做些什么吗?

NetworkCredential creds = new NetworkCredential();

creds.UserName = "partner_client";
creds.Password = "dfasnc9d3";
HttpWebRequest hwRequest = (HttpWebRequest)HttpWebRequest.Create("https://res.dfadator.com/rest/requests/recent");
hwRequest.ContentType = System.Configuration.ConfigurationManager.AppSettings.Get("ContentType");
hwRequest.Method = System.Configuration.ConfigurationManager.AppSettings.Get("Method"); ;

hwRequest.Credentials = creds;

// Parse the Response.
webResponse = (HttpWebResponse)hwRequest.GetResponse();

1 个答案:

答案 0 :(得分:0)

上述方法调用代理服务器,如果代理服务器设置启用了UseProxy 我在拨打电话时绕过代理服务器解决了这个问题。

string sProxyWebAddress = null;
System.Net.WebProxy wbProxy = new System.Net.WebProxy(sProxyWebAddress, true);
hwRequest.Proxy = wbProxy;
wbProxy = null;