久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

沒有“Access-Control-Allow-Origin"標頭 - Laravel

No #39;Access-Control-Allow-Origin#39; header - Laravel(沒有“Access-Control-Allow-Origin標頭 - Laravel)
本文介紹了沒有“Access-Control-Allow-Origin"標頭 - Laravel的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

XMLHttpRequest 無法加載 http://myapi/api/rating.對預檢請求的響應未通過訪問控制檢查:請求的資源上不存在Access-Control-Allow-Origin"標頭.Origin 'http://localhost:8104' 因此不允許訪問.響應的 HTTP 狀態代碼為 403.

XMLHttpRequest cannot load http://myapi/api/rating. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8104' is therefore not allowed access. The response had HTTP status code 403.

我不明白為什么我不能發出 CORS 請求.我已經在這里安裝了中間件,將它添加到全局http內核中,但它仍然不起作用.嘗試根據 stackoverflow 建議創建自定義中間件,但這也不起作用.還嘗試添加一個路由組.最后,我嘗試在請求操作中手動設置響應標頭.我真的被困住了 - 感謝幫助!

I can't figure out why I can't make CORS requests. I've install the middleware here, added it to the global http kernel, but it still doesn't work. Tried to create a custom middleware given stackoverflow suggestions but that also did not work. Also tried adding a Route group. Lastly, I tried setting the response headers manually in the request action. I'm really stuck - help is appreciated!

查看代碼:https://gist.github.com/KerryRitter/0d7ababb7b9eb8d54f0ae55

推薦答案

如果你使用的是 Laravel 5.5 &Laravel 5.x 并面臨同樣的問題,如請求的資源上不存在Access-Control-Allow-Origin"標頭.只需使用以下軟件包并配置您的系統.

If you are using Laravel 5.5 & Laravel 5.x and facing same problem like No 'Access-Control-Allow-Origin' header is present on the requested resource. Just use following package and config your system.

第 1 步:

composer require barryvdh/laravel-cors

第 2 步

您還需要將 CorsServiceProvider 添加到您的 config/app.php providers 數組:

You also need to add CorsServiceProvider to your config/app.php providers array:

FruitCakeCorsCorsServiceProvider::class,

要允許所有路由使用 CORS,請在 app/Http/Kernel 的 $middleware 屬性中添加 HandleCors 中間件.php 類:

To allow CORS for all your routes, add the HandleCors middleware in the $middleware property of app/Http/Kernel.php class:

供全球使用:

protected $middleware = [
    // ...
    FruitcakeCorsHandleCors::class,
];

中間件用途:

protected $middlewareGroups = [
   'web' => [
       // ...
   ],

   'api' => [
        // ...
        FruitcakeCorsHandleCors::class,
    ],
];

第三步

安裝完成后,運行以下命令以發布供應商文件.

Once your installation completed run below command to publish the vendor files.

php artisan vendor:publish --provider="FruitcakeCorsServiceProvider"

希望這個回答能幫助和我一樣面臨同樣問題的人.

Hope this answer helps someone facing the same problem as myself.

這篇關于沒有“Access-Control-Allow-Origin"標頭 - Laravel的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

add new element in laravel collection object(在 Laravel 集合對象中添加新元素)
Creating an edit modal in Laravel 5(在 Laravel 5 中創建編輯模式)
Laravel 5.5 API resources for collections (standalone data)(用于集合的 Laravel 5.5 API 資源(獨立數據))
What is the best practice to create a custom helper function in php Laravel 5?(在 php Laravel 5 中創建自定義輔助函數的最佳實踐是什么?)
Laravel Passport Route redirects to login page(Laravel Passport Route 重定向到登錄頁面)
How create package in Laravel 5?(如何在 Laravel 5 中創建包?)
主站蜘蛛池模板: 日韩一区二区三区在线 | 国产精品久久久久久久久久久久 | 一级毛片视频在线观看 | 久久综合一区 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 国产免费a视频 | 4h影视 | 国产精品乱码一区二区三区 | 国产99久久 | 高清免费av | 香蕉久久久 | 成人精品啪啪欧美成 | 日韩中文字幕一区二区 | 国产成人精品一区二区三区视频 | 国产黄色在线观看 | 91成人免费看| 在线精品观看 | 美国十次成人欧美色导视频 | 午夜视频在线免费观看 | 免费观看的黄色网址 | 久久精品二区亚洲w码 | 美女爽到呻吟久久久久 | 日韩成人在线观看 | 成人一区二区三区视频 | 国产欧美一区二区精品忘忧草 | 久久久美女| www.亚洲精品 | 国产精品一区二区久久 | 国产精品国产亚洲精品看不卡15 | 在线国产视频 | 99re视频在线 | 亚洲成a人片 | 久久久久久亚洲精品 | 天天看逼| 91www在线观看| 亚洲一区精品在线 | 超碰人人人 | 午夜精品久久久久久久久久久久久 | 在线视频一区二区 | 亚洲色图第一页 | 一区二区三区四区在线 |