【发布时间】:2021-05-28 03:21:33
【问题描述】:
尝试从 Angular 应用程序调用执行器端点时收到 CORS 错误。
我知道我可以在 Spring Boot 应用程序的 application.yaml 中启用 CORS 允许的来源。
但我想知道的是,如果我从 Spring Boot 应用程序中发出请求,我不会收到 CORS 错误。
从 http://localhost:8080 执行的以下行返回有效响应。
var response = new RestTemplate().getForEntity("https://<HOST>/actuator/info", String.class);
从我的 Angular 应用程序执行此行时,出现 CORS 错误
this.httpClient.get('https://<HOST>/actuator/info').subscribe((result: any) => {
console.log(result);
});
这两个调用都来自 localhost,来自 Angular 的一个会导致 CORS 错误,而来自 Spring Boot 的一个不会。
谁能给我解释一下这个区别?
【问题讨论】:
-
感谢您的回答,它不是重复的。在链接的帖子中,它是关于节点服务器应用程序中的一般 CORS。我的问题是关于从 Angular 应用程序(客户端)和 Spring Boot 应用程序(也是客户端)向同一服务器发送 HTTP 请求时的不同行为
标签: angular spring-boot httpclient resttemplate