Javascript 我无法将reactjs fetch和nodejs作为REST API项目读取服务器端的授权头

Javascript 我无法将reactjs fetch和nodejs作为REST API项目读取服务器端的授权头,javascript,reactjs,Javascript,Reactjs,我无法使用reactjs fetch作为前端调用api的方式在服务器端获取头。在旧项目中,它运行良好 我的后端代码没有更改,这是什么原因 this.setState({ isProcessing: true }); fetch(env.apis.getUsersList, reqOptions) .then(res => res.json()) .then((data) => { this.setState({ us

我无法使用reactjs fetch作为前端调用api的方式在服务器端获取头。在旧项目中,它运行良好 我的后端代码没有更改,这是什么原因

      this.setState({ isProcessing: true });  
      fetch(env.apis.getUsersList, reqOptions)
      .then(res => res.json())
      .then((data) => {
        this.setState({ users: data });  
      })
      .catch((error) => {
           debugger
      });
   }
这就是我传头球的方式

var reqOptions = {
        method: actionType,
        headers: new Headers({ 
            'Content-Type': 'application/json',
            'authorization': 'Bearer ' + localStorage.token
       }), 
    };
    // debugger
    // if (localStorage.token) {
        // reqOptions.headers.authorization = 'Bearer ' + localStorage.token;   
    // }
    if (data) {
        reqOptions.body = JSON.stringify(data);
    }
    return reqOptions;
    
正在获取此错误消息 error=TypeError:获取失败

在浏览器中,基本上显示的是正在显示的临时标题

这是错误的


问题出在服务器端,NodeJ的CORS设置已修复,类似的操作已修复

var cors = require('cors'); 
app.use(cors({credentials: true}));

“Authotization”你在说什么?不要在reqOptions中添加“方法”和“标题”,只需添加
var reqOptions={authorization:“Bearer”+localstorage.token}
yes也尝试了,但没有成功。我将主题更改为新主题,现在这种情况正在发生。可能与reactjs版本或sone设置有关。