I am calling localhost URL using C# HttWebRequest. It is returning a 503 service unavailable error in response.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("http://127.0.0.1:42000/some/path"));
req.Method = "POST";
byte[] postArray = Encoding.UTF8.GetBytes("");
req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
req.ContentLength = postArray.Length;
req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
response = (HttpWebResponse)req.GetResponse();
On a different computer it is working fine and also on web browser localhost URL is opening. Localhost is connected to AWS EC2 instance using tunnel on some port. What is cause of this issue?
I found out reason for it. Issue was due to
HttpWebRequestwas picking up system proxy automatically. So I set Proxy null inHttpWebRequestobject in codereq.Proxy = null;before making request. Issue was fixed after this.