预检请求未通过访问控制

时间:2020-04-05 18:47:49

标签: reactjs axios

我遇到错误

对预检请求的响应未通过访问控制检查:它没有HTTP正常状态。

first = async  () =>  {
         const data = {
                firstName:'abcdef',lastName:'defghi'
           
        };
         const resp = await axios({
               
                method:'post',
                url: 'url here' ,
                data,
            }
        );
            console.log(resp);

我只能更改前端代码。任何帮助将不胜感激?

1 个答案:

答案 0 :(得分:0)

似乎需要客户端请求标头:

    first = async  () =>  {
     const data = {
            firstName:'abcdef',lastName:'defghi'

    };
    const resp = await axios({
            method:'post',
            url: 'url here' ,
            data: data,
            headers: {
               'Allow-control-allow-origin': 'domain permitted here',
               'Authorization': 'authorization here'
               //eg: 'Aurhorization': 'Basic: ' + window.btoa(generatedCredentials);
            }
        }
    );
    console.log(resp);