How to pass a post with an array to a Webform URL

Asked

Viewed 265 times

2

I’m trying to send an array with some elements in a post to a url.

I called 'Webbroser' method, passed the parameters, but still I had no idea how to finish implementing.

Follows my code:

   private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("MINHA_URL");
        request.Method = "POST";
        request.Accept = "application/json";
        request.UserAgent = "curl/7.37.0";
        request.ContentType = "application/x-www-form-urlencoded";

        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            string data = "browser=Win7x64-C1|Chrome32|1024x768&url=http://www.google.com";

            streamWriter.Write(data);
        }

    }
    private void label2_Click(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        var lista = new string[]
        {
            info.nome,
            info.idade,
              info.estado= "H",
           //DAQUI PRA BAIXO JÁ É PRÉ-DEFINIDO

            info.regiao,
            info.tipousuario = "X",
            info.formulario = "0",
            info.t = "+",
            info.v = "",
            info.pop = "",
            info.t= "",
            info.p= "",
            info.t= "x",
            info.r= "x",
            info.e= "2",
            info.f= "n",
            info.id= ""
        };

         webBrowser1_DocumentCompleted(lista, null);
    }

    #region inputs
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        info.estado= textBox1.Text;
    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

        info.nome= textBox2.Text;
    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {
        info.idade= textBox3.Text;
    }
    #endregion
  • I don’t understand what your doubt is.

  • So gypsy. I have a URL that will receive a post from an array. What I want is to send this post that is in button1_Click for the webBrowser1_DocumentComplete method.

  • And then what? What happens?

  • I want this url, run with the parameters that was sent to it.

1 answer

0

Apparently everything is right. All that remains is to collect the answer:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("MINHA_URL");
    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=http://www.google.com";

        streamWriter.Write(data);
    }

    WebResponse response = request.GetResponse();
}
  • Thanks, I’ll test it as soon as I can. And I’ll give you feedback. Thank you!

  • The following error occurred:' The underlying connection was closed: The connection was closed unexpectedly.'

  • This bug happens by some different feature in the return header. Try using request.KeepAlive = false;. I’ve updated my answer.

  • continues to give the error "The connection has been closed..." and another question. in string data = "browser=Win7x64-C1|Chrome32|1024x768&url=MINHA_URL"; In this part of "my_url" I put the url q step in Create, n is?

Browser other questions tagged

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