react项目本地跨域(webpack+axios)
react项目本地跨域(webpack+axios)
遇到一个需求:要去访问内网里另一个域名的后端接口,比如https://www.aaa.com的域名去访问http://www.bbb.com。
一开始是这样写的
axios({
method: 'GET',
url: 'http://www.bbb.com/user/xiaoming',
data: {
StaffSn: '4927493',
},
}).then((result) => {
// 返回的结果
}).catch((err) => {
// 出错了
});
然后浏览器报错 :Mixed Content: The page at https://www.aaa.com’ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘http://www.bbb.com/user/xiaoming’. This request has been blocked; the content must be served over HTTPS.
报错的原因是:https网站去访问http网站,是不允许,被认为不安全的。
搜了一下解决方法,网上推荐最多的解决方法是
在页面中加入 meta 头:
<meta http-equiv=