【发布时间】:2018-10-05 16:42:42
【问题描述】:
我正在使用 HTTPClient 将 JSON 对象发送到 REST Web 服务,我正在捕获响应,但我只获取日志中的标头,而不是响应正文中的 JSON 响应。
相关代码如下
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.PostAsync("https://example.com/api/checkout", new StringContent(transaction.ToString(), System.Text.Encoding.UTF8, "application/json"));
log.Info("response is " + response);
如何从响应中的正文捕获 JSON 响应?
【问题讨论】:
-
通过从响应对象中读取(例如
await response.Content.ReadAsStringAsync())?