首页 > 解决方案 > angular6:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 Access-Control-Allow-Origin

问题描述

使用后端 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);
  }

在此处输入图像描述 在这里添加图片请帮助。

标签: angular6yii2-advanced-app

解决方案


看起来像cors问题,

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


推荐阅读