gpt4 book ai didi

angularjs - 跨域请求阻止的Elasticsearch

转载 作者:行者123 更新时间:2023-12-01 14:41:39 25 4
gpt4 key购买 nike

嗨,我正在运行Elasticsearch 2.3版,并且我有一个Angular代码可以像search.query一样查询。当我运行它时,即使http.cors.enabled设置为true,并且http.cors.allow-origin设置为/https?:\/\/localhost(:[0-9]+)?/,我也会收到此错误

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:9200/elastic/_search?size=50. This can be fixed by moving the resource to the same domain or enabling CORS

我不明白问题是什么。

我的请求 header 。
    User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0
Pragma: no-cache
Origin: http://127.0.0.1:8100
Host: localhost:9200
Connection: keep-alive
Cache-Control: no-cache
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

我的控制台看起来像这样。
enter image description here

但是,如果我将请求直接放在这样的浏览器中..我会得到正确的输出。

enter image description here

最佳答案

通过将这些行添加到yml中,然后重新启动ES,我已经解决了该问题。

 http.cors.enabled : true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length
http.cors.allow-credentials: true

关于angularjs - 跨域请求阻止的Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37384380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com