gpt4 book ai didi

vue.js - Vue axios 发布请求被 CORS 策略阻止

转载 作者:行者123 更新时间:2023-12-03 06:42:57 25 4
gpt4 key购买 nike

Vue axios 发布请求

axios.post(`${this.host}:${this.port}/apiv2/login`, {
body: {
userName: this.user,
password: this.pwd
}
});

导致错误:

Access to XMLHttpRequest at 'http://localhost:9047/apiv2/login' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

python 请求、postman 或简单的 curl 可以无误地完成工作

curl 'http://localhost:9047/apiv2/login' -H 'Content-Type: application/json' --data-binary '{"userName":"user","password":"pass"}'

更新:这是我的解决方案:

我添加了 NodeJS 服务器 (localhost:8081)。现在 Vue (localhost:8080) 正在访问 NodeJS,而 NodeJS 正在查询 Dremio API (localhost:9047)。

只有静态 Vue 应用的想法行不通。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com