C# HttpClient PostAsync with parameters

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;
            }
        }

 

上一篇:5.2 imnoise函数


下一篇:2019第三届强网杯线下3道RW