(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:
Cheers!
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);
Comments
Post a Comment