我正在使用 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 响应?
您需要从内容流中读取正文
var json = await response.Content.ReadAsStringAsync();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句