• 周四. 10 月 3rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

.net HttpClient 向 WebApi Post 的方法

admin

11 月 28, 2021

public void HttpClientPost()
{
  using (var client = new HttpClient())
  {
    client.BaseAddress = new Uri(this.txtUrl.Text);
    var content = new FormUrlEncodedContent(new[]
    {
      new KeyValuePair<string, string>(“loginName”, “name”),
      new KeyValuePair<string, string>(“psw”, “psw”),
    });
    var result = client.PostAsync(this.txtUrl2.Text, content).Result;
    string resultContent = result.Content.ReadAsStringAsync().Result;
    Console.WriteLine(resultContent);
  }
}

发表回复