当我尝试使用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