Donate

(502)Bad Gateway Returned From HttpWebRequest In C#

The solutions is to set the default proxy for the web request and assign user agent to it as shown below:
ListURL = String.Format("your_xml_feed_or_API_url_sample");  
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ListURL);  
request.Timeout = 900000000;  
request.Proxy = HttpWebRequest.DefaultWebProxy;  
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";  

HttpWebResponse response = (HttpWebResponse)request.GetResponse();  
Stream dataStream = response.GetResponseStream();  
dataStream = response.GetResponseStream();  
StreamReader reader = new StreamReader(dataStream);  
ListingSource = reader.ReadToEnd();  
ListingSource = System.Web.HttpUtility.HtmlDecode(ListingSource);
Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.