按官方文档 //官方允许跨域操作,在EasySwooleEvent.php中注册此方法
public static function onRequest(Request $request, Response $response): bool
{
// TODO: Implement onRequest() method.
$response->withHeader('Access-Control-Allow-Origin', '*');//允许所有跨域
$response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
$response->withHeader('Access-Control-Allow-Credentials', 'true');
$response->withHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
if ($request->getMethod() === 'OPTIONS') {
$response->withStatus(Status::CODE_OK);
return false;
}
return true;
}
设置之后 仍无法解决跨域请求
题目描述
题目来源及自己的思路
相关代码
粘贴代码文本(请勿用截图)