Dibakar
Dibakar

Reputation: 1

Preflight Request doesn't pass access control

I am getting error

Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

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

I can only change in front-end code. Any help would be appreciated?

Upvotes: 0

Views: 131

Answers (1)

OO7
OO7

Reputation: 690

It seems that needs client request headers:

    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);

Upvotes: 1

Related Questions