[英]Fetching URL through proxy returns 403 error
With the goal of avoiding all the CORS headaches, I setup my vue cli to proxy the API call through webpack: 为了避免所有CORS头痛,我设置了vue cli以通过webpack代理API调用:
config/index.js 配置/ index.js
proxyTable: {
'/api': {
target: 'https://remote',
changeOrigin: true,
'^/api': '/api'
}
},
Visiting the URL directly in browser works, for example: http://localhost:8080/api/events
直接在浏览器中访问URL即可,例如: http://localhost:8080/api/events
However, if I try to fetch the url with axios, I get a 403 error: Error: "Request failed with status code 403"
但是,如果尝试使用axios提取URL,则会收到403错误: Error: "Request failed with status code 403"
Unfortunately the only reference I could find is this open issue . 不幸的是,我唯一可以找到的参考是这个未解决的问题 。
In my case, it doesn't work in Firefox or Chrome. 就我而言,它在Firefox或Chrome中不起作用。
This is a vue-cli 2 project, axios 0.18.0
, vue 2.5.2, webpack
3.6.0 , webpack-dev-server
2.9.1` 这是一个vue-cli 2项目,axios 0.18.0
,vue 2.5.2, webpack
3.6.0 , webpack-dev-server
2.9.1`
Ah I see, in case it benefits anyone, for some reason, setting my API url as localhost was not working: 嗯,我知道,如果出于某种原因使任何人受益,请将我的API URL设置为localhost不起作用:
.env .ENV
API_URL=//localhost:8080/api
But the following works: 但是以下工作原理:
.env .ENV
API_URL=//127.0.0.1:8080/api
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.