目前我正在研究JHipster 3(从JHipster 2迁移)。我的一些模块是从RESFTful请求获取JSON数据的。
这里是JHipster 2中的示例代码: - > (工作)
'use strict';
angular.module('newsletterApp')
.factory('UserBirthday', function ($resource) {
return $resource('http://localhost:8081/BirthDay/Rest/WebService/GetFeeds', {}, {
'query': {method: 'GET', isArray: true},
'get': {
method: 'GET',
isArray: true,
transformResponse: function (data) {
data = angular.fromJson(data);
return data;
}
}
});
});
对于Jhipster 3:
(function(){
'use strict';
angular
.module('newsletterApp')
.factory('EmployeeBirthday', EmployeeBirthday);
EmployeeBirthday.$inject = ['$resource'];
function EmployeeBirthday($resource){
return $resource('http://localhost:8081/BirthDay/Rest/WebService/GetFeeds', {}, {
'query': {method: 'GET', isArray: true},
'get': {
method: 'GET',
isArray: true,
transformResponse: function (data) {
data = angular.fromJson(data);
return data;
}
}
});
} })();
我得到了错误:
XMLHttpRequest cannot load http://localhost:8081/BirthDay/Rest/WebService/GetFeeds. 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.
在application.yml中也已启用CORS
cors: #By default CORS are not enabled. Uncomment to enable.
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800
有什么建议可以解决这个问题吗?
答案 0 :(得分:0)
allowed-origin(例如http://localhost:9000),并且不能将Wildcard *与allow-credentials结合使用:true。