I have successfully set cors
middleware with Laravel as describer here
Therefore, this ajax call is ok
axios.get('http://my_domain/api/my_api')
But when trying to send token like this:
axios.get('http://my_domain/api/my_api',
{
headers: {
Authorization: 'Bearer aaa.bbb.ccc'
}
})
I get a cors erros saying Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have even added Access-Control-Allow-Headers
in the middleware, I still have the issue.
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Log;
class Cors {
public function handle($request, Closure $next) {
Log::info("Using cors for ".$request->url());
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Authorization');
}
}
Can anyone help please?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire