-5

I trying to connect to awesemo.com using c# http request but its http connection failing by showing the following error: Error1: IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Error2: SocketException: An existing connection was forcibly closed by the remote host.

I tried to access many other sites including Google.com all are worked fine but above website and one squarespace website connection failed. But one month before all were working fine. This is the new problem I facing. I tried lots in testing different codes as well as changed the framework but still unable to fix.

Here is my code: (All lines except the comment lines are copied from fiddler after a successful web request to above website using chrome browser.)

    private void test()
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.awesemo.com/");

        request.KeepAlive = true;
        request.Headers.Add("Upgrade-Insecure-Requests", @"1");
        request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
        //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
        request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9");
        request.Headers.Set(HttpRequestHeader.Cookie, @"_ga=GA1.2.523834838.1531216658; __stripe_mid=93850985-96a8-491e-b6ee-8c4b3147f3ab; _tccl_visitor=1fa9b919-5361-46be-9fb2-00cccf35c249");
        //System.Net.ServicePointManager.Expect100Continue = false;
        //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    }
Kalpataru Mallick
  • 83
  • 1
  • 3
  • 10
  • Is this an ad for the website? – PepitoSh Jul 12 '18 at 09:41
  • Read [ask] and show what you have tried. If you want to programmatically access a website and it refuses that, you must make sure your request looks like a legitimate request. Compare all headers from an succeeding request with a failing request. – CodeCaster Jul 12 '18 at 09:42
  • @Pepitosh No its not not ads. I removed the link if you thinking so. – Kalpataru Mallick Jul 12 '18 at 09:53
  • 1
    Works for me too, perhaps whatever it is your doing has caused them to block your IP address. – Alex K. Jul 12 '18 at 10:34
  • @mjwills Thanks. yes console app working fine but in winform its not working. – Kalpataru Mallick Jul 12 '18 at 10:39
  • I would suggest removing code from your winforms until it starts working. Whatever the last thing you removed == the bit that is making it not work. – mjwills Jul 12 '18 at 10:43
  • @mjwills Yes when I separated code to a different winform project it worked fine. I think the problem is in my existing projects code. Thanks all for your valuable suggestion. This is seems to be very simple problem but made me lots of headache from many days. – Kalpataru Mallick Jul 12 '18 at 10:55

1 Answers1

1

After lots of testing I figure out the problem which was the .NET framework version. The framework version was 4.5 and after I updated it to 4.6 it solved my problem.

Kalpataru Mallick
  • 83
  • 1
  • 3
  • 10