lundi 24 août 2020

CORS error: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request [duplicate]

please someone to help me,i'm facing this error

Access to fetch at 'http://url/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

while trying to access laravel api in reactjs app on shared hosting but local is working

reactjs code

fetch("http://schoolcbapi.schoolcountbook.rw/api/authuser/",{

        method:"POST",
        mode:"cors",
        headers:{
          "Content-Type":"Application/json",
          "Accept":"Application/json",
        },
        body:JSON.stringify({
          "email":this.state.email,
          "password":this.state.password
        })
      })

laravel middleware

public function handle($request, Closure $next)
{
    $response = $next($request);

    $response->header("Access-Control-Allow-Origin","*");
    $response->header("Access-Control-Allow-Credentials","true");
    $response->header("Access-Control-Max-Age","600");    // cache for 10 minutes

    $response->header("Access-Control-Allow-Methods","POST, GET, OPTIONS, DELETE, PUT"); //Make sure you remove those you do not want to support

    $response->header("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization, X-Requested-With, Application");

    return $response;
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire