亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React + Laravel 7 API - CORS 問題

React + Laravel 7 API - CORS 問題

PHP
料青山看我應如是 2023-07-08 16:35:35
我正在嘗試制作一個簡單的注冊表單(只是在學習),但我遇到了 CORS 問題。我已經嘗試了所有我發現的東西,但沒有一個起作用。據我所知,Laravel 7 已經可以防止 CORS 問題,但我的卻不能。這是我的代碼:api.php<?phpuse Illuminate\Http\Request;use Illuminate\Support\Facades\Route;/*|--------------------------------------------------------------------------| API Routes|--------------------------------------------------------------------------|| Here is where you can register API routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| is assigned the "api" middleware group. Enjoy building your API!|*/Route::group([    'prefix' => 'auth',], function () {    Route::post('login', 'AuthController@login');    Route::post('signup', 'AuthController@signup');    Route::group([        'middleware' => 'auth:api'    ], function () {        Route::get('logout', 'AuthController@logout');        Route::get('user',  'AuthController@user');    });});Route::middleware('auth:api')->get('/user', function (Request $request) {    return $request->user();});cors.php<?phpreturn [    /*    |--------------------------------------------------------------------------    | 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/*'],    'allowed_methods' => ['*'],    'allowed_origins' => ['*'],    'allowed_origins_patterns' => [],    'allowed_headers' => ['*'],    'exposed_headers' => [],    'max_age' => 0,    'supports_credentials' => false,];
查看完整描述

1 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

我通過在 axios 請求中添加“http://”解決了這個問題。



查看完整回答
反對 回復 2023-07-08
  • 1 回答
  • 0 關注
  • 135 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號