如何解决请求的资源上不存在“Access-Control-Allow-Origin”标头 Angular Elasticsearch Kibana
我已经向 Kibana API 端点实施了 http post 请求 (Angular),但出现以下错误。
从源“http://YY.YY.Y.YYY:YYYY”访问“http://XX.XXXXX:XXXX/internal/security/login”的 XMLHttpRequest 已被 CORS 阻止策略:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
这是 Angular 代码
const headers = new HttpHeaders({
'Content-Type': 'application/json','kbn-version': '7.6.2'});
const body = {
username: 'username1',password: 'password1'
};
return this.http.post('http://XX.X.X.XXX:XXXX/internal/security/login',body,{ headers });
这是elasticsearch.yml
cluster.name: Cluster
http.port: 9200
network.host: XX.X.X.XXX
node.data: true
node.ingest: false
node.master: true
node.max_local_storage_nodes: 1
node.name: Nodo_1
path.data: C:\Monitoring\elasticsearch\elasticsearch-7.6.2\data
path.logs: C:\Monitoring\elasticsearch\elasticsearch-7.6.2\logs
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS,HEAD,GET,POST,PUT,DELETE
http.cors.allow-headers: kbn-version,Origin,X-Requested-With,Content-Type,Accept,Engaged-Auth-Token,Authorization,Content-Length
这是kibana.yml
server.port: 5601
server.host: "XX.X.X.XXX"
xpack.security.enabled: true
elasticsearch.hosts: ["http://XX.X.X.XXX:XXXX"]
elasticsearch.username: "username2"
elasticsearch.password: "password1"
解决方法
发生此问题是因为 CORS 起源。您需要在跨域标头属性下允许源源。
我更喜欢在服务器端处理这个问题,而不是在客户端实现一些东西
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。