• 周六. 4月 27th, 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);
  }
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注