5 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
我正在使用 Laravel 8
檢查配置/cors.php
將路徑數(shù)組更改為 * ('paths' => ['*'])

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊
我也遇到了同樣的問題,通過中間件解決了
定義您的自定義中間件
//App\Http\Middleware;
public function handle($request, Closure $next)
{
? ? return $next($request)
? ? ? ? ->header('Access-Control-Allow-Origin', '*')
? ? ? ? ->header('Access-Control-Allow-Methods', '*')
? ? ? ? ->header('Access-Control-Allow-Credentials', true)
? ? ? ? ->header('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type,X-Token-Auth,Authorization')
? ? ? ? ->header('Accept', 'application/json');
}
不僅僅是注冊(cè)您的中間件,本地(針對(duì)特定路線)或全局。

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
這對(duì)我來說工作:
php artisan make:middleware OwnCors
創(chuàng)建的中間件代碼:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class OwnCors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
header("Access-Control-Allow-Origin: *");
$headers = [
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization'
];
if ($request->getMethod() == "OPTIONS") {
return response('OK')
->withHeaders($headers);
}
$response = $next($request);
foreach ($headers as $key => $value)
$response->header($key, $value);
return $response;
}
}
將中間件添加到您的 App\Http\Kernel.php 中
protected $middleware = [
\App\Http\Middleware\OwnCors::class,
// Others middlewares
];

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
對(duì)于 Laravel 8
就我而言,我添加了需要訪問資源的源。
// config/cors.php
// add a path to the resource here if you want it accessible to external origins
// for example no need to explicitly tell allowed origins
// what origins should gain access to api/* routes
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
// explicitly tell which origins needs access to the resource
'allowed_origins' => ['*', 'https://mywebsite.com', 'http://mywebsite.com'],
// or use regex pattern, helpful if you want to grant
// access to origins with certain pattern (i.e. an origin under a subdomain etc.)
'allowed_origins_patterns' => ['/https?:\/\/mywebsite\.com\/?\z/'],
// no changes made below
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
php artisan optimize另外,如果您正在緩存配置,請(qǐng)不要忘記運(yùn)行。

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
如果您正在開發(fā) Outlook 插件,您需要檢查的事項(xiàng):
檢查您是否已在 manifest.xml 中包含域名,在我的情況下,我需要包含https://test.com以包含在 <AppDomain> 標(biāo)記中。
您的域名應(yīng)該有 ssl 證書。(即)outlook 允許您僅通過 https 請(qǐng)求。
- 5 回答
- 0 關(guān)注
- 703 瀏覽
添加回答
舉報(bào)