public PostAsync ( |
||
requestUri | ||
content | ||
return | Task |
using System; using System.Net.Http; using System.Threading.Tasks; public class Program { public static async Task Main() { var client = new HttpClient(); var uri = new Uri("https://example.com/api/data"); var data = new { id = 1, name = "John Doe" }; var json = Newtonsoft.Json.JsonConvert.SerializeObject(data); var payload = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, payload); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } }
using System; using System.Net.Http; using System.Threading.Tasks; public class Program { public static async Task Main() { var client = new HttpClient(); var uri = new Uri("https://example.com/api/login"); var content = new FormUrlEncodedContent(new [] { new KeyValuePairThis example sends a username and password in a form-urlencoded format to the specified URI and prints the response received from the server. Package library: System.Net.Http.("username", "johndoe"), new KeyValuePair ("password", "password123") }); var responseMessage = await client.PostAsync(uri, content); var response = await responseMessage.Content.ReadAsStringAsync(); Console.WriteLine(response); } }
public PostAsync ( |
||
requestUri | ||
content | ||
return | Task |