Angular-无法设置标题

时间:2019-02-01 15:06:36

标签: angular amazon-web-services aws-api-gateway amazon-cognito

我试图从Angular发出get请求时设置标头,但是它不起作用。路由是正确的,我已经使用REST客户端(失眠)对其进行了测试,一切正常。

这是我的Angular代码:

const options = {
  headers: {
    Authorization: 'XXXXXXXXXXXXX'
  }
};

this.http.get(this.endpoint, options).subscribe((data) => {
  console.log(data);
}, (error) => {
  console.log(error);
});

我检查了endpointoptions,但看不到任何问题。我总是收到错误代码401和以下消息:

Access to XMLHttpRequest at XXXXXX from origin YYYYYYYYY has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

我还正确地在API网关上启用了CORS,当我从界面中删除授权程序时,它可以正常工作

这就是我的要求:

Chrome request status

0 个答案:

没有答案