Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI,
I am trying to invoke api service using post and iam getting excetion like
"
C#
The remote server returned an error: (407) Proxy Authentication Required.

"
My Code: worked in out of office network and not working in my office network.

C#
// Restful service URL
            string url = @"https://url/url";

            var filePath = @"..\PostXML.xml";

            ASCIIEncoding encoding = new ASCIIEncoding();
            string strResult = string.Empty;

            string SampleXml = File.ReadAllText(filePath);
            string postData = SampleXml.ToString();

            byte[] data = encoding.GetBytes(postData);

            HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);

            webrequest.Method = "POST";

            webrequest.ContentType = "application/soap+xml";

            webrequest.ContentLength = data.Length;

            webrequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("username:password"));
            webrequest.Headers.Add("Client-Id", "2345678igfdfguio");
            webrequest.Headers.Add("Client-Secret", "490iugfghjki-ltyhjvb");
            Stream newStream = webrequest.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();

            Encoding enc = System.Text.Encoding.GetEncoding("utf-8");

            StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);

            strResult = loResponseStream.ReadToEnd();

            loResponseStream.Close();

            webresponse.Close();

            strResult = strResult.Replace("</string>", "");


            Console.Write(strResult);


What I have tried:

I tried by passing proxy values with credentials but not helped, please with any sugessions.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900