本地主机上的Access-Control-Allow-Origin(Laravel& Vue)CORS CORB错误 [英] Access-Control-Allow-Origin (Laravel & Vue) CORS CORB error on localhost
问题描述
我使用了这个包,但它没有用( https://github.com/barryvdh/laravel-cors )
I use this package and it didn't work (https://github.com/barryvdh/laravel-cors)
addSMS() {
axios.post('https://smsmisr.com/api/webapi', {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, GET, PUT, OPTIONS, DELETE',
'Access-Control-Allow-Headers': 'Access-Control-Allow-Methods, Access-Control-Allow-Origin, Origin, Accept, Content-Type',
'Content-Type': 'application/json',
'Accept': 'application/json'
},
username: '*****',
passowrd: '****',
etc: '',
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
请告诉我如何解决它,因为它对我不起作用.
please tell me how to fix it it's cors not working for me.
推荐答案
由于您无法访问API的源代码,因此与.htaccess
或在脚本中添加'Access-Control-Allow-Origin': '*',
无关.但是您仍然可以通过以禁用的安全模式打开chrome浏览器来消除此错误
As you have no access in API's source code so there is nothing to do with .htaccess
or adding 'Access-Control-Allow-Origin': '*',
in script. But still you can eradicate this error by opening chrome browser with disabled security mode
在Windows中运行CMD(同时按下Windows按钮和键盘上的R
键.然后在框中键入cmd
并输入).
In windows run CMD (press together windows button and R
key from keyboard. Then type cmd
in box and enter).
然后转到C
驱动器(在CLI中)或chrome的安装位置(使用cd
命令),然后运行以下命令
Secondly go to C
drive (in CLI) or where your chrome installed (using cd
command) then run following command
"Program Files (x86)\Google\Chrome\Application\chrome.exe" –-allow-file-access-from-files --disable-web-security --user-data-dir --disable-features=CrossSiteDocumentBlockingIfIsolating
它将以禁用的网络安全模式打开浏览器.完成后,您现在就可以测试这种CORS
或CORB
错误.
It will open your browser in disabled web security mode. Once you done it you can test now with this kind of CORS
or CORB
error.
注意:在运行此命令之前,请确保没有打开任何镶边.
note: before running this command make sure there are no chrome are opened already.
Program Files (x86)\Google\Chrome\Application\chrome.exe
这应该是您的chrome安装路径
Program Files (x86)\Google\Chrome\Application\chrome.exe
this should be your chrome installed path
但是,打开浏览器后,它将显示如下,不要惊慌&不要关闭此消息.如果您关闭此消息,它将再次通过此CORS
或CORB
错误
However after opening browser it will show as below, dont panic & dont close this message. if you close this message it will again through this CORS
or CORB
error
这篇关于本地主机上的Access-Control-Allow-Origin(Laravel& Vue)CORS CORB错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!