How to fill forms and submit with Webclient in C#

前端 未结 6 989
忘了有多久
忘了有多久 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 03:24

    Posting a form with System.Net.Http.HttpClient and reading the response as string:

    var formData = new Dictionary();
    formData.Add("number", number);
    
    var content = new FormUrlEncodedContent(formData);
    
    using (var httpClient = new HttpClient())
    {
        var httpResponse = await httpClient.PostAsync(theurl, content);
    
        var responseString = await httpResponse.Content.ReadAsStringAsync();
    }
    

提交回复
热议问题