當我嘗試使用POSTMAN和配置授權參數(kermit:kermit)發送GET請求到Activiti REST URL時,它的作用就像一個魅力。Activiti REST在GET請求後返回401
但是,當我試圖做同樣的事情,只有角$ http服務,它將返回以下錯誤:
XMLHttpRequest cannot load http://localhost:8080/activiti-rest/service/repository/deployments . 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:8081 ' is therefore not allowed access. The response had HTTP status code 401.
這裏是我的控制器:
(function() {
'use strict';
angular
.module('doktorat-app-test')
.controller('TestController', TestController);
TestController.$inject = ['$http', '$base64'];
function TestController($http, $base64) {
var tcr = this;
$http.defaults.headers.common['Authorization'] = 'Basic ' + $base64.encode('kermit:kermit');
tcr.text = 'ssdsds';
$http.get('http://localhost:8080/activiti-rest/service/repository/deployments')
.then(function(response){
tcr.text = response.data;
});
}
})();
有沒有人遇到了類似的錯誤? 花了超過2天試圖解決此問題,但沒有任何成功。
P.S.我正在使用NodeJS http-server來運行我的Angular App,它運行在8081端口上。
https://stackoverflow.com/search?q=No+Access-Control-Allow-Origin+header+is +現在+ + +請求+資源 – sideshowbarker