S
S
sa1ch2021-02-07 09:45:03
PHP
sa1ch, 2021-02-07 09:45:03

How to enable CORS in public API?

Hello.
The question is:

I make a request using axios, there I pass only 2 headers, Authorization and Content-Type.

I wrote the following on the server:

$response
    ->setHeader("Access-Control-Allow-Origin", "*")
    ->setHeader("Access-Control-Allow-Methods", "GET, POST, PUT")
    ->setHeader("Access-Control-Allow-Headers", "*")
    ->setHeader("Access-Control-Allow-Credentials", true)
    ->sendHeaders();


In response, we get an error: "No 'Access-Control-Allow-Origin' header is present on the requested resource."

If the Authorization header is removed from the request, then the server normally accepts the request and returns a response.
I tried to register the domain in Access-Control-Allow-Origin, I tried to specify the necessary headers in Access-Control-Allow-Headers. I can't figure out what's the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question