【问题标题】:angular6:Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight responseangular6:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 Access-Control-Allow-Origin
【发布时间】:2019-06-05 19:02:16
【问题描述】:

使用后端yii2高级框架,使用POST方法调用api请求报错为:请求头字段Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response。

const BASE_API_URL = 'http://localhost/harshini/kpa/backend/frontend/web/index.php?r=site%2Flogin';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json',
  'Access-Control-Allow-Origin': '*'})
};
sendValue(message: Kpa) {
    return this.http.put(BASE_API_URL, message, httpOptions);
  }

这里正在添加图片,请帮忙。

【问题讨论】:

  • 请任何人帮我解决这个问题,我在过去四天里一直在这个问题上。

标签: angular6 yii2-advanced-app


【解决方案1】:

看起来像cors 问题,

从服务器端启用cors。 请参考此链接Yii2 cors filters error that No 'Access-Control-Allow-Origin' header is present

【讨论】:

  • 我已经在服务器端启用了 cors,但仍然出现同样的错误。@AmolBJamkar
  • 您的图像显示 Access-Control-Allow-Origin 标头在预检呼叫响应中不存在,这意味着您需要添加它 Access-Control-Allow-Origin:* 或启用 cors 来处理它。再次检查您的选项调用。
猜你喜欢
  • 2016-04-24
  • 2016-05-15
  • 2019-12-12
  • 2018-03-02
  • 2020-02-27
  • 2016-05-10
  • 2019-02-21
  • 1970-01-01
  • 2017-12-02
相关资源
最近更新 更多