我正在尝试向 Oauth 的 API 发送响应。遗憾的是,Symfony2 文档在解释 $response->headers->set(...);
的所有不同部分方面做得很差。
这是我的 OauthController 中的响应部分:
$response = new Response();
$response->setStatusCode(200);
$response->headers->set('Location', 'url=' . $auth_url);
return $response->send();
Controller 必须有一个 return
语句,所以我的代码看起来不错,或者我如何从普通 php 复制 header('Location: ' . $auth_url);
?
谢谢!
请您参考如下方法:
既然要做重定向,那么可以用RedirectResponse
而不是常规的 Response
:
return new RedirectResponse($auth_url);