【问题标题】:AngularJS HTTP headers config. Response for preflight has invalid HTTP status code 401AngularJS HTTP 标头配置。预检响应具有无效的 HTTP 状态代码 401
【发布时间】:2016-09-16 09:33:04
【问题描述】:

我正在尝试使用 angular 获取 Rest 服务:

angular.module('coursExoApp').factory('serviceAjax', function ($http) {
return{
    objects: function(){
         var test=$http({
            method: 'GET',
            url: 'http://------------/Windchill/servlet/rest/changes/objects/getReports',
            headers: {
                'Authorization': 'Basic d2NhZG1pbjp3Y2FkbWlu'           
            }
            }).
            success(function(data, status, headers, config) {
                console.log('success');
            }).
            error(function(data, status, headers, config) {
                console.log(config);
            });

            return test;
    }
}});

我收到了这个错误: IMAGE HERE

具有基本身份验证的服务在 postMan 上运行良好。 感谢帮助

【问题讨论】:

    标签: angularjs xmlhttprequest


    【解决方案1】:

    听起来像是 CORS 的问题,也许您需要修改服务以允许请求的来源(您的应用运行的域)?

    Chrome v37/38 CORS failing (again) with 401 for OPTIONS pre-flight requests

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

    【讨论】:

      猜你喜欢
      • 2017-03-15
      • 2018-07-01
      • 2017-07-02
      • 2023-04-10
      • 2018-10-02
      • 2016-10-10
      • 2018-06-17
      • 2016-02-08
      • 2016-11-14
      相关资源
      最近更新 更多