【发布时间】:2019-04-20 16:17:49
【问题描述】:
我有这个通用方法,用于执行 Post 请求,然后像这样解析响应。
private async Task<object> PostAsync<T1,T2>(string uri, T2 content)
{
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri))
{
var json = JsonConvert.SerializeObject(content);
using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
{
requestMessage.Content = stringContent;
HttpResponseMessage response = await _client.SendAsync(requestMessage);
if (response.IsSuccessStatusCode)
{
_logger.LogInformation("Request Succeeded");
T1 responseModel = JsonConvert.DeserializeObject<T1>(await response.Content.ReadAsStringAsync());
return responseModel;
}
else
{
return await GetFailureResponseModel(response);
}
}
}
}
现在的问题是一些 Post 请求响应在 SnakeCase 中,而另一些在 CamelCase 中。我该如何解决这个问题。
【问题讨论】:
标签: c# json asp.net-core