当前网址:http://127.0.0.1:8000/
当我试图向http://127.0.0.1:9000/
发送请求时,它提供了net::ERR_CONNECTION_REFUSED
或net::ERR_CONNECTION_RESET
。但是,当我试图在浏览器中单独调用时,http://127.0.0.1:9000/
工作正常。其他API正在正常工作。原因是什么?我怎样才能解决这个问题?
我的守则:
axios.get('http://127.0.0.1:9000')
.then((response) => {
console.log(response);
})
vue
3.2.31
axios
0.25.0
发布于 2022-04-03 15:43:22
我们得到一个CORS策略错误,因为我们在我们的bootstrap.js中有这些默认的头
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
您应该删除axios中的一个请求的默认标头。您可以在请求中使用transformRequest
:
axios.get('xxxx.com', { transformRequest: [(data, headers) => {
delete headers.common['X-Requested-With'];
return data
}] })
.then((response) => {
console.log(response);
})
https://stackoverflow.com/questions/71701032
复制相似问题