D
D
diafree2020-01-29 15:44:46
JavaScript
diafree, 2020-01-29 15:44:46

"CORS preflight channel failure" - how to solve?

Good afternoon.

The following headers have been added to .htaccess:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Allow-Headers "append,delete,entries,foreach,get,has,keys,set,values,Authorization"
</IfModule>


Result:
Request from foreign origin blocked: The single origin policy prohibits reading the remote resource on site.api. (Reason: CORS preflight channel failure).

Request from foreign origin blocked: The single origin policy prohibits reading the remote resource on site.api. (Reason: CORS request failed).


Tell me, please, how can I solve?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Athanor, 2020-01-30
@diafree

preflight requests are made from another host and the method is OPTIONS.
In general, you have everything written correctly and the check will depend on where and how you host the service. In general, the steps are as follows:
1. If you write these directives in .htaccess, then make sure that you have AllowOverride All set in /etc/apache2 configs and .htaccess is picked up.
2. Make sure you have mod_headers enabled by running the a2enmod headers command.
3. Use, for example, https://www.test-cors.org/ to check if access has been granted.
If you have this on shared hosting and you cannot follow these steps, contact technical support with your question on how to solve this problem.
Good luck in solving the issue)
Sincerely,
Ivan Tomilov
CEO of Athanor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question