【发布时间】:2019-12-23 21:15:33
【问题描述】:
我使用 RestTemplate 在 Spring Boot 中创建应用程序 - API 客户端。 API(不是我的)可能有 CORS,因为在控制台中我得到 403,但在浏览器/邮递员中是可以的。 如何绕过 CORS?
public Pokemontcg getPokemontcg() {
RestTemplate restTemplate = new RestTemplate();
Pokemontcg forObject = restTemplate.getForObject("https://api.pokemontcg.io/v1/cards?name=charizard", Pokemontcg.class);
return forObject;
}
结果
"main" org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden
【问题讨论】:
-
你在哪里得到 CORS 错误?
-
用一点代码更新你的问题
-
curl 的请求运行良好。您应该检查一次完整的错误响应。 API 正在使用 cloudflare 进行保护。您可能会在以下问题中找到解决方案:stackoverflow.com/questions/54367327/…
标签: spring-boot