gpt4 book ai didi

javascript - 如何解决跨源读取阻止 (CORB) 阻止的跨源响应和跨源错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:01 25 4
gpt4 key购买 nike

var bodyFormData = new FormData();
bodyFormData.set("data", "C://Users//harshit.tDownloads\\weather.csv");
bodyFormData.set("type", "text-intent");
//axios.post("https://api.einstein.ai/v2/language/datasets/upload",

axios({
method: 'post',
url: 'https://xxxx/v2/language/datasets/upload',
data: bodyFormData,
mode: 'bodyFormData',
//dataType:'json',
headers: {
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Headers':'*',
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer IFMEWWRWLJGTOSBWIJFEIQSCJJFVIVSEG5NEWNSKIRGTOTKQIRKDMUKQGJBFETCFJ5GUENSSIJHUEQJWIFHE4NSWIZHE6TCFGVJUMV2VLFIUKVSPKBMEMNKRGVJFMU2KIRIUUQKMIFIU2R2ZGNJFSTSRIQZEUN2GIVFFC7COIE',
'Cache-Control': 'no-cache',
'Access-Control-Allow-Credentials' : true,

'Access-Control-Allow-Methods':'POST',

'Accept':'application/json, text/plain, */*'

}
})
.then(function (response) {
//handle success
console.log("1111111",response);
})
.catch(function (response) {
//handle error
console.log(response);
});

如何解决从 axios 调用 api 时跨域读取阻止 (CORB) 阻止的跨域响应和跨域错误,我收到 CORS 错误,请检查上面的代码

最佳答案

如果您可以控制nodejs服务器,则可以在使用npm install cors安装后使用下一个中间件

var cors = require('cors');
app.use(cors());

Documentation

关于javascript - 如何解决跨源读取阻止 (CORB) 阻止的跨源响应和跨源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59630890/

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