How to fill forms and submit with Webclient in C#

前端 未结 6 977
忘了有多久
忘了有多久 2020-11-29 03:03

I\'m new at using the the libraries WebClient, HttpResponse and HttpRequest in C#, so bear with me, if my question is confusing to read.

I need to build a WinForm ba

6条回答
  •  萌比男神i
    2020-11-29 03:35

    Try this:

    using System.Net;
    using System.Collections.Specialized;  
    
    NameValueCollection values = new NameValueCollection();
    values.Add("TextBox1", "value1");
    values.Add("TextBox2", "value2");
    values.Add("TextBox3", "value3");
    string Url = urlvalue.ToLower();
    
    using (WebClient client = new WebClient())
    {
        client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        byte[] result = client.UploadValues(Url, "POST", values);
        string ResultAuthTicket = System.Text.Encoding.UTF8.GetString(result);
    }
    

提交回复
热议问题