【问题标题】:JHipster 3 error during CORS requestCORS请求期间的JHipster 3错误
【发布时间】:2016-08-09 15:59:12
【问题描述】:

目前我正在开发 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

有解决这个问题的建议吗?

【问题讨论】:

    标签: angularjs rest cors jhipster


    【解决方案1】:

    allowed-origin 必须指定(例如http://localhost:9000)并且不能是通配符 * 与 allow-credentials: true 组合。

    【讨论】:

      猜你喜欢
      • 2019-03-10
      • 2021-11-02
      • 2019-07-17
      • 2014-05-26
      • 2017-06-29
      • 2019-09-15
      • 1970-01-01
      • 2023-03-21
      • 2017-05-04
      相关资源
      最近更新 更多