We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

CORS policy

Hello!

Try using vue js pass in the backend:

...
axios.post('https://mysite.ru', dataSend, {
    headers: {
        'Content-Type': 'application/json',
        Accept: 'application/json'
    }
})
...

Phalcon:

...
$app->response
    ->setHeader("Access-Control-Allow-Origin", '*')
    ->setHeader("Access-Control-Allow-Methods", 'GET,PUT,POST,DELETE,OPTIONS')
    ->setHeader("Access-Control-Allow-Headers", '*')
    ->setHeader("Access-Control-Allow-Credentials", true)
    ->send();
...

I get the error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

unless the request to remove the content-type is no error. what is the problem?

Check the DevTools - what headers is your browser receiving with the response?



4.3k

ANNOTATIY-2020-06-16-114316.th.png

I have no response headers.

but if I remove the: 'Content-Type': 'application/json' then the problem disappears

Check the DevTools - what headers is your browser receiving with the response?

You've got to have some response headers - otherwise no response is coming in.

Did you see this post; https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check ?



4.3k

I do not understand. why if you remove header "Content-Type" then comes the answer?

You've got to have some response headers - otherwise no response is coming in.

Did you see this post; https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check ?