【发布时间】:2019-11-09 02:41:27
【问题描述】:
嗨,我正在运行 Elasticsearch 2.3 版,我有一个 Angular 代码可以像搜索一样查询。当我运行它时,即使 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
我不明白问题出在哪里。
我的请求标头。
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
但是如果我像这样直接将请求放在浏览器中..我会得到正确的输出。
【问题讨论】:
-
您是通过 file:/// 协议加载页面还是由本地主机上的 Web 服务器提供服务?可以找到类似的问题here
-
通过 file://...这有什么不同吗???
-
如果您阅读我分享的链接,您会发现它有所不同,因为从文件系统加载时 Origin 为空。您可能会通过升级到 2.3.3 来摆脱困境,因为我认为他们已经解决了这个 CORS 问题。
-
我尝试通过安装一个简单的 http 服务器来运行。但仍然是同样的问题,我正在运行 Elasticsearch 2.3.3
-
您能否使用 HTTP 请求 + 响应中的请求标头更新您的问题?