我正在使用LaravelSanctum Axios API創建 react js 專案。當我獲得注冊頁面時,它顯示以下錯誤。
cors.php
<?php
回傳 [
/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your settings for cross-origin resource sharing
| or "CORS". This determines what cross-origin operations may execute
| in web browsers. You are free to adjust these settings as needed.
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
*/
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
];
錯誤
從源“http://localhost:3000”訪問“http://localhost:8000/sanctum/csrf-cookie”的 XMLHttpRequest 已被 CORS 策略阻止:對預檢請求的回應未通過訪問控制檢查:它沒有 HTTP ok 狀態。
xhr.js:210
獲取 http://localhost:8000/sanctum/csrf-cookie net::ERR_FAILED
createError.js:16
Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:117)
uj5u.com熱心網友回復:
您在服務器應用程式上MUST啟用CORS。了解如何Laravel做到這一點。
這個問題可能對你有幫助。 Laravel CORS
uj5u.com熱心網友回復:
您需要授予對前端 localhost 的訪問權限以向后端 API 發送請求。
所以我建議你仔細按照 laravel 網站的說明進行操作:https ://laravel.com/docs/8.x/sanctum#spa-configuration
如果您對某些步驟有任何疑問,可以問我。
但我認為你的問題是你的前端 URL 不能發送請求,你必須允許它。但無論如何,首先你必須按照鏈接中的步驟操作
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/372186.html
標籤:反应 拉拉维尔 运行时错误 laravel-sanctum csrf-token
