mardi 24 septembre 2019

Access to XMLHttpRequest at 'abc.com' from origin 'xyz.com' has been blocked by CORS policy No 'Access-Control-Allow-Origin'

i have tried cors middleware and similiar laravel packages its , but cant access outside url , some body can give good solution

kernel.php

\App\Http\Middleware\Cors::class,

Cors Middlware

public function handle($request, Closure $next)


{
    header("Access-Control-Allow-Origin: *");
    //ALLOW OPTIONS METHOD
    $headers = [
        'Access-Control-Allow-Methods' => 'POST,GET,OPTIONS,PUT,DELETE',
        'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization',
    ];
    if ($request->getMethod() == "OPTIONS"){
        //The client-side application can set only headers allowed in Access-Control-Allow-Headers
        return response()->json('OK',200,$headers);
    }
    $response = $next($request);
    foreach ($headers as $key => $value) {
        $response->header($key, $value);
    }
    return $response;

}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire