🌈 搜索
📅 最后修改于: 2022-03-11 14:57:07.931000 🧑 作者: Mango
private async Task PostToAPI(object myObject, string endpointUri, string endpointDirectory) { string myObjectAsJSON = System.Web.Helpers.Json.Encode(myObject); StringContent stringContent = new StringContent(myObjectAsJSON, Encoding.UTF8, "application/json"); using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(endpointUri); using (HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(endpointDirectory, stringContent).ConfigureAwait(false)) { // Do something } } }