Michal Habalcik

Michal Habalcik

  • NA
  • 3.5k
  • 2.4m

C# HttpWebRequest timing out from USA IPs, fine in browsers

Apr 11 2018 11:31 AM

I am struggling with web requests to some websites like (mrporter.com or size.co.uk). Outside USA (so no USA IPs), I can make requests just fine. However once I am behind USA IP, requests either time out or end up with "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond" exception. I have tried all kind of headers combinations, still no luck. I need to note, that those websites are opening in browsers just fine.
This is my implementation that works with non-USA ips.
  1. var _request = (HttpWebRequest)WebRequest.Create("https://www.mrporter.com");                  
  2. _request.CookieContainer = new CookieContainer();  
  3. _request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";  
  4. _request.KeepAlive = true;  
  5. _request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);  
  6. _request.Headers.Add("Accept-Encoding""gzip, deflate");  
  7. _request.Headers.Add("Accept-Language""en-GB, en-US; q=0.9, en; q=0.8");  
  8. _request.Headers.Add("Upgrade-Insecure-Requests""1");  
  9.   
  10. var _srr = "";  
  11. using (var response = _request.GetResponse())  
  12. {  
  13. var httpWebResponse = response.GetResponseStream();  
  14. using (var sr = new StreamReader(httpWebResponse))  
  15. {  
  16. _srr = sr.ReadToEnd();  
  17. }  
  18. }  
 
Anybody can help? I seriously wasted hours with it with no result ...

Answers (1)