angular6 - 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);
}
解决方案
看起来像cors
问题,
cors
从服务器端启用。请参考此链接Yii2 cors filters error that No 'Access-Control-Allow-Origin' header is present
推荐阅读
- generics - 不拥有的泛型参数的生命周期范围
- javascript - 如何刷新翻译以响应短语应用程序
- python - 在 Visual Studio 2019 中导入 python 包的问题
- python - 计算字符串 Python 中的总元音或辅音
- vuetify.js - 如何使 vuetify v-menu 项目可使用 tab 键导航
- css - 当它被点击时,它周围有默认的奇怪边框,如何删除它?
- python - Python Lollipop Plot,在线写标签
- asp.net-core - 通过 REST API 上传文件(图像、视频、.docx、.pdf、...)
- reactjs - 将材质ui文本字段标签放在Border的右上角而不是左边
- java - 如何访问没有标识符的 JSON 字段