码迷,mamicode.com
首页 > Windows程序 > 详细

C# HttpClient PostAsync with parameters

时间:2020-03-24 11:13:23      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:class   using   string   ons   orm   syn   system   tpc   ada   

using System.Net.Http;
 static void Main(string[] args)
        {
            var httpTask = Task<string>.Run<string>(() =>
            {
               return MainAsync();
            });
            httpTask.Wait();   
            Console.WriteLine(httpTask.Result);
            Console.ReadLine();
        }

        static async Task<string> MainAsync()
        {
            using (var client = new HttpClient())
            {                     
                List<KeyValuePair<string, string>> kvpsList = new List<KeyValuePair<string, string>>();
                kvpsList.Add(new KeyValuePair<string, string>("k1", "v1"));
                kvpsList.Add(new KeyValuePair<string, string>("k2", "v2"));
                var formContent = new FormUrlEncodedContent(kvpsList);                
                var result = await client.PostAsync(url, formContent);
                string resultContent = await result.Content.ReadAsStringAsync();
                return resultContent;
            }
        }

 

C# HttpClient PostAsync with parameters

标签:class   using   string   ons   orm   syn   system   tpc   ada   

原文地址:https://www.cnblogs.com/Fred1987/p/12557113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!