我有这个通用方法,用于执行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中。我该如何解决这个问题。
互换的青春
相关分类