无法使用基本身份验证和CORS进行api后调用

时间:2019-02-15 16:15:36

标签: authentication post cors axios

我正在使用axios进行api调用,通过了基本身份验证以及设置了标头,但收到以下错误:

从原点“ https://api.lotlinx.com/photoai/v1/optimize”到“ http://localhost:3000”的XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态。

Following is the post call :

// endpoint and postBody are already defined.
axios.post(endpoint, postBody, {
    auth: {
        username: 'testaccount4',
        password: 'b784dd85d16b'
    },
    headers: {
        'Access-Control-Allow-Origin': 'http://localhost:3000',
        'Access-Control-Allow-Methods': 'GET, POST, OPTIONS'
    }
    }).then(function(response) {
    console.log('Authenticated');
}).catch(function(error) {
    console.log('Error on Authentication');`enter code here`
});

任何人都可以帮助解决此问题。

0 个答案:

没有答案
相关问题