【发布时间】:2019-12-27 02:27:52
【问题描述】:
我调用我的 https REST APi,它使用 Postman 在另一台服务器上调用 http api,它返回 502 bad gateway 错误。 https API 的身份验证在标头中设置,并且也接受:应用程序/json。所有其他不在远程服务器上调用 ohter http api 的 https rest api 都可以正常工作。
我已经使用 SpringBoot 创建了带有身份验证的 REST API。有 GET 和 POST 方法。它们都有像 https://...这样的 URL。在调用它们之前,用户必须获得一个安全令牌。这些 Rest api 可用作驻留在部署在 tomcat 中的 Server_1 上的 war 文件。从许多 API 中,我调用了作为 jar 文件驻留在另一个 Server_2 上的另一个 Rest 服务,其 URL 的 URL 类似于 http://...。当我调用驻留在 Server_1 上的 war 文件中的一个 https rest api 时,请求进入 Server_2。 Server_2 上的 Http rest api 使用 JSON 文件回答。我可以在 Server_2 的日志中看到它,而且我已经捕获了服务器之间的 http 流量。看起来 http rest api 接收到请求并将答案发回,但是来自 Server_1 的 https RestApi 拒绝了答案,因为它没有加密并给出错误的网关 502 错误。有什么办法可以解决这个错误?
//这就是我在服务器2上调用http rest api的方式。这段代码是服务器1上https rest api的一部分(tomcat中的war文件)
public ResponseEntity<String> function()
{
RestTemplate restTemplate = new RestTemplate();
String myUrl = "http://xxxxxx:8081";
ResponseEntity<String> response = restTemplate.getForEntity(myUrl + "/api/test/suspend/12", String.class);
return responce
}
【问题讨论】: