0
我有一個REST Web服務需要基本身份驗證才能使用其數據。我正在AngularJS中使用它。如何在AngularJS的休息服務中傳遞基本認證?
我這樣做是如下的方式:
$http.get('http://localhost:9200/persons/_search?_source=Gender', {
headers: {
withCredentials: true,
headers:{ 'Authorization': 'Basic ' + btoa("admin" + ":" + "admin")}
}
}).
then(function(response) {
ctrl.json = response.data;
});
}]);
但是我在控制檯時遇到的錯誤是:
請求頭字段標題不被 訪問 - 允許預檢響應中的Control-Allow-Headers。
有人可以幫助解決這個問題嗎?請注意,我已經在郵遞員上進行過測試,並且工作正常,所有數據都正確返回給我。
我已經允許。但問題依然存在。任何替代品? – jones
你是怎麼答的? – Sletheren
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,Content-Type,Content-Length,X-User「 我在配置文件中添加了上述行。 – jones