using System.Net.Http; static async TaskGetRequest(string url) { using (var client = new HttpClient()) { using (var response = await client.GetAsync(url)) { using (var content = response.Content) { string result = await content.ReadAsStringAsync(); return result; } } } }
using System.Net.Http; static async TaskIn this example, the PostRequest() method sends an HTTP POST request to the specified URL with the given data and returns the response as a string. The package library used in these examples is the System.Net.Http library.PostRequest(string url, Dictionary data) { using (var client = new HttpClient()) { var content = new FormUrlEncodedContent(data); using (var response = await client.PostAsync(url, content)) { using (var responseContent = response.Content) { string result = await responseContent.ReadAsStringAsync(); return result; } } } }