我这里有一个 Laravel 8.75 应用程序,我正在尝试从我的 vue SPA 向我的 Laravel 后端工作发出发布请求。我在线检查了许多不同的线程,但找不到我丢失的东西。 GET 请求工作。这里没有cors错误。然而,post request get cors issues.
Access to XMLHttpRequest at 'http://localhost:8000/api/web3-login-verify' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我有一个全新的 Laravel 安装。我添加的唯一包是:
https://github.com/fruitcake/laravel-cors
我的内核.php:
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
...
];
我的 cors.php 配置文件:
return [
'paths' => ['api/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
我在 routes/api.php 中的路线
Route::get('/web3-login-message', [Web3LoginController::class, 'message']);
Route::post('/web3-login-verify', [Web3LoginController::class, 'verify']);
在我的前端,我只是下载了“axios”。除了添加一些错误处理之外,我没有对其进行太多配置。我正在这样发送我的请求:
const getUser = await axios.post(`${BACKEND_API}/api/web3-login-verify`, {
address,
signature
})
有人有想法吗?