📜  stringcontent 对象 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:07.931000             🧑  作者: Mango

代码示例1
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
        }
    }
}