spring-boot - 为什么restTemplate.exchange的响应返回null?
问题描述
我有打击代码,我的网络服务运行良好,但不返回响应:
ResponseEntity<Object> reponse=null;
try {
reponse = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Object.class);
} catch (HttpStatusCodeException e) {
System.out.println("reponse="+reponse);
}
我的问题是,为什么
回复
为空但
restTemplate.exchange(url, HttpMethod.POST, requestEntity, Object.class)
不为空?
解决方案
我在响应实体中错误地搜索错误。但它在例外情况下可用。
} catch (HttpClientErrorException e) {
System.out.println(e.getStatusCode());
System.out.println(e.getResponseBodyAsString());
}
推荐阅读
- python - 使用 Numpy 为 sklearn 设置良好的随机化环境
- algorithm - 二维矩阵能否以比 O(n^2) 更好的时间复杂度旋转 90°?
- spring - Spring:有没有关于不可重复数据的注释?
- javascript - 如何使用 ssjs 将日期中的时间替换为 xpage 中字符串字段中的时间?
- security - 报告了未分配 CVE 的 Jfor XrayVulnerabilities
- azure - 如何登录到天蓝色从文件中获取令牌
- azure-ad-b2c - 在 B2C 中预先创建用户并发送“重置密码流程”-预先填充的电子邮件
- python - 使用 Python Selenium 抓取动态内容
- python - 在 Python 中,当您使用“,”将两个值分配给一行中的两个变量时,它会如何反应?
- c++ - 显示“?” 而不是 C++ Windows 中的 unicode 字符