在某些网络中需要代理身份验证(407)



我尝试了以下代码来解决代理身份验证问题。但问题仍然存在。 注意:某些网络不使用代理,它工作正常。

var INI = new IniFile(@"Settings.ini");
String scredUserName = INI.Read("UserName", "Credentials");     
String sPassword = INI.Read("Password", "Credentials");        
String sAPIKey = INI.Read("APIKey", "Credentials");

string sUserNamePassword = scredUserName + ":" + sPassword;
byte[] byteUserNamePassword = System.Text.ASCIIEncoding.ASCII.GetBytes(sUserNamePassword);
string encodedUserNamePassword = System.Convert.ToBase64String(byteUserNamePassword);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", 
encodedUserNamePassword);
client.DefaultRequestHeaders.Add("aw-tenant-code", sAPIKey);
String sProxyUserName = INI.Read("UserName", "Proxy Authentication");
String sProxyPassword = INI.Read("Password", "Proxy Authentication");
string sProxyUserNamePassword = sProxyUserName + ":" + sProxyPassword;
byte[] byteProxyUserNamePassword = System.Text.ASCIIEncoding.ASCII.GetBytes(sProxyUserNamePassword);
string encodedProxyUserNamePassword = System.Convert.ToBase64String(byteProxyUserNamePassword);
client.DefaultRequestHeaders.Add("Proxy-Authorization", "Basic " + encodedProxyUserNamePassword);

发布我问题的答案:- 我应该将代理凭据与代理地址一起传递。

WebProxy wbProxy = new WebProxy();
Uri newUri = new Uri(sProxyAddress);
wbProxy.Address = newUri; 
wbProxy.Credentials = new NetworkCredential(sProxyUserName, sProxyPassword);
client.Proxy = wbProxy;

相关内容

  • 没有找到相关文章

最新更新