C# HttpClient PostAsync with parameters

2021-03-13 06:31

阅读:653

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

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

        static async Taskstring> MainAsync()
        {
            using (var client = new HttpClient())
            {                     
                Liststring, string>> kvpsList = new Liststring, string>>();
                kvpsList.Add(new KeyValuePairstring, string>("k1", "v1"));
                kvpsList.Add(new KeyValuePairstring, 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


评论


亲,登录后才可以留言!