Answer the question
In order to leave comments, you need to log in
How to disable preflight requests?
I noticed that before making a request to my server, the browser first makes some kind of pre-request with the OPTIONS type and in fact it turns out that the download speed suffers because of this and I get a response 2 times slower.
Is it possible to somehow disable preflight requests for cross-domain requests?
What I tried to do:
<?php
// Если это предзапрос:
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
// Отдаем только заголовки, без тела:
header('access-control-allow-origin: *');
header('access-control-allow-methods: *');
header('access-control-allow-headers: *');
header('access-control-expose-headers: *');
// Указываем закешировать предзапрос:
header('access-control-max-age: 600');
}
Answer the question
In order to leave comments, you need to log in
It might be easier to not do things that cause preflight requests. In particular, Content-Type: application/json
you can send the request as text/plain
.
https://developer.mozilla.org/en-US/docs/Web/HTTP/...
I don't know why the developers of CORS decided application/json
it was dangerous.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question