Closed rondaful closed 6 years ago
我想直接修改response的header值,让它后面一直有效下去。
$response = $response->withAddedHeader('Access-Control-Allow-Origin','*');
$response = $response->withAddedHeader('Access-Control-Allow-Credentials','true');
$response = $response->withAddedHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD,PATCH');
$response = $response->withAddedHeader('Access-Control-Allow-Headers', 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since,Captcha,Lang');
这样子解决了,但合适吗???
可以写链式调用
$response = $response->withHeader('Access-Control-Allow-Origin','*')
->withHeader('Access-Control-Allow-Credentials','true')
->withAddedHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD,PATCH')
->withAddedHeader('Access-Control-Allow-Headers', 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since,Captcha,Lang');
return $response;
base.php 有配,下面是middleWare.类。 为什么请求没有带上 Access-Control-Allow-Origin Access-Control-Allow-Methods 这些header