The underlying connection was closed: The connection was closed unexpectedly

Asked

Viewed 4,011 times

2

I have a Webform project, and I’m passing an array to a method that will post to a specific URL. However, after I run the project and send the array to the method, it breaks with the error reported in the title.

   private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://MINHAURL.COM/QUE-RECEBE-O-POST/");
        request.Method = "POST";
        request.Accept = "application/json";
        request.UserAgent = "curl/7.37.0";
        request.ContentType = "application/x-www-form-urlencoded";
        request.KeepAlive = false;

        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            string data = "browser=Win7x64-C1|Chrome32|1024x768&url=https://MINHAURL.COM/QUE-RECEBE-O-POST/";

            streamWriter.Write(data);
        }

        WebResponse response = request.GetResponse();

    }

    private void button1_Click(object sender, EventArgs e)
    {
         var user = new Usuarios();
        var lista = new string[]
        {
            user.name,
            user.dt_nascimento,
            user.cidade
        };

        webBrowser1_DocumentCompleted(lista, null);
    }
  • I don’t know exactly what the problem is. But it starts wrong by using a method to notify event as a normal method of execution. Dá sends him nonsense. And he doesn’t even use what he was told, so send it to what? Probably the site you want to access requires something that is not being passed on, such as SSL, for example, or is not even an accessible location. If the address is https://wwww.minhaurl.com/ really the error is consistent. Otherwise, you would have to pass more information to be able to answer.

  • @bigown there is a specific url that will receive this post. This "minhaurl" that I passed, is just the example. Both, as the array I pass below, are fictitious.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.