Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
domain.com ha sido bloqueado por la política CORS: la respuesta a la solicitud de verificación previa no pasa la verificación de control de acceso: no tiene el estado HTTP correcto

Manejar las solicitudes de verificación previa de la aplicación React a Symfony se está volviendo demasiado difícil ahora, estoy tratando de solucionar esto durante las últimas 8 horas, este es el error que recibo,

Access to XMLHttpRequest at 'https://mylocaldomain.com/validate-token' from origin 'http://myreactapplocal:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Intenté agregar el código de esta publicación aquí en public/index.php y funcionó, estoy tratando de implementar lo mismo en el oyente ya que no quiero editar public/index.php y no funciona a través del oyente , a continuación está mi código de oyente

 namespace App\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\KernelEvents; class CorsListener implements EventSubscriberInterface { private $container; public function __construct(ContainerInterface $container) { $this->container = $container; } public static function getSubscribedEvents(): array { return [ RequestEvent::class => 'onRequestEvent', ResponseEvent::class => 'onResponseEvent', ]; } public function onRequestEvent(RequestEvent $event) { if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { return; } $request = $event->getRequest(); $method = $request->getRealMethod(); if ('OPTIONS' === $method) { $response = new Response(); $response->headers->set('Access-Control-Allow-Headers', 'X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization'); $event->setResponse($response); } } public function onResponseEvent(ResponseEvent $event) { // Don't do anything if it's not the master request. if (!$event->isMasterRequest()) { return; } $response = $event->getResponse(); $response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE'); $response->headers->set('Access-Control-Allow-Headers', 'Content-Type,Authorization'); } }

¡Se agradece cualquier tipo de ayuda / pista para resolver este problema!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

También tuve este problema al usar angular y symfony.

Para mí, poner el siguiente código en index.php lo resolvió

 header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Headers: *"); header("Access-Control-Allow-Methods: *"); header("Allow: *"); $method = $_SERVER['REQUEST_METHOD']; if ($method === "OPTIONS") { die(); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!