Я пытаюсь подключить мой Restful API, созданный с помощью Elastic Search, используя xmlhttp в javascript.Тем не менее, когда я делаю запрос, я получаю следующие ошибки:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.56.1:8080' is therefore not allowed access.
И это вторая ошибка;
OPTIONS http://serveripaddress//elasticsearch/users/user/_search 401 (Unauthorized)
Я добавил эти разрешения вasticseach.yml
http.cors.enabled: "true"
http.cors.allow-origin: "/.*/"
http.cors.allow-credentials: "true"
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"
Запрос был сделан после этого кода:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://serveripaddress/_search', true);
xhr.withCredentials = true;
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'Basic ' + btoa('test:test'));
xhr.send('{"query":{"match_all":{}}}');
Я также хочу уточнить, чтоasticsearch размещен в облачной виртуальной машине Google, и что я тестирую свой проект в localhost http://192.168.56.1:8080.