0

i tried below code to resolve the proxy authentication issue. But still the issue is persist. Note: Some networks without using Proxy, it is working fine.

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);

1 Answer 1

0

Posting the answer for my questions:- I should have passed Proxy credentials along with proxy address.

                    WebProxy wbProxy = new WebProxy();
                    Uri newUri = new Uri(sProxyAddress);

                    wbProxy.Address = newUri; 

                    wbProxy.Credentials = new NetworkCredential(sProxyUserName, sProxyPassword);
                    client.Proxy = wbProxy;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.