React JS和laravel passport POST方法成功地实现了OPTIONS



当我试图在react js自定义头中添加授权代码时POST方法更改为OPTION

fetch('http://localhost:8000/api/user/save', {
method : 'POST',
headers: {
'Accept' : 'application/json',
'Content-Type' : 'application/x-www-form-urlencoded',
'Authorization' : 'Bearer ' + sessionStorage.getItem('token')
},

body : formBody
})
.then(response => response.json())
.then(response => {
}).catch((err) => {
alert('Something is error   ! ');
});

注意:我想使用交叉原点。我在localhost:3000上的react应用程序和我的服务器localhost:8000

这是因为CORS,如果您的API和前端生活在同一个项目上,您可以将http://localhost:8000/api/user/save更改为/api/user/save

您也可以禁用CORS。

最新更新