React JS 和 laravel passport POST 方法更改为 OPTIONS

React JS and laravel passport POST method chenged to OPTIONS

当我试图在 react js 自定义中添加授权代码时 header .. 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 和服务器 localhost:8000

上的 React 应用程序

这是因为 CORS,如果您的 API 和前端位于同一个项目中,您只需将 http://localhost:8000/api/user/save 更改为 /api/user/save

您也可以禁用 CORS。