HttpClient PostAsJsonAsync 实现

public static async Task<HttpResponseMessage> PostAsJsonAsync<TModel>(this HttpClient client, string requestUrl, TModel model)
{
    var serializer = new JavaScriptSerializer();
    var json = serializer.Serialize(model);
    var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
    return await client.PostAsync(requestUrl, stringContent);
}

  接收端:

public System.Net.Http.HttpResponseMessage FnRecv([FromBody]TModel ts)
posted on 2021-04-29 18:27  wakaka_wka  阅读(883)  评论(0编辑  收藏  举报