我正在使用angularjs製作一個web應用程序。我正在對elasticsearch API進行請求。這是代碼:使用angularjs請求彈性搜索作爲跨域
app.controller('usersDatas', function($scope, $http){
$http.post("http://192.168.6.55:9200/userdata/_search", {headers : { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
data: "{ 'query': { 'query_string': { 'query': 'png' } } }"
// Access-Control-Allow-Origin: true
}).success(function(data){
console.log(data);
});
});
這是錯誤我:
XMLHttpRequest cannot load http://192.168.6.55:9200/userdata/_search. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
我加入了這一點:
http.cors:
enable: true
allow-origin: /https?:/\/\/localhost(:[0-9]+)?/
我elasticsearch(/etc/elasticsearch/elasticesarch.yml)配置。我不知道問題是來自elasticsearch還是來自angularjs。 我該如何解決這個問題? 謝謝。
ü使用基於Windows或Linux的系統或ios? – Gopinath
我使用的是Ubuntu 16.04 – theCode