【发布时间】:2018-03-17 05:02:02
【问题描述】:
$request = new Symfony\Component\HttpFoundation\Request()
$request->getRequestUri();
似乎返回路径和查询参数。如何获得路径?
【问题讨论】:
$request = new Symfony\Component\HttpFoundation\Request()
$request->getRequestUri();
似乎返回路径和查询参数。如何获得路径?
【问题讨论】:
$request->getPathInfo() 就是你要找的东西。
【讨论】:
strtok($request->getRequestUri(), '?');
...或...
$request->getBaseUrl() . $request->getPathInfo();
【讨论】:
或者您也可以只使用 PHP:
$urlWithoutQueryString = strtok($_SERVER["REQUEST_URI"], '?');
【讨论】:
以上方法在 Laravel 5.7 中都不适合我。我最终使用以下内容来获取不带查询字符串的完整请求 URI:
$uri = strtok($request->getUri(), '?');
这将返回 https://example.com/request/uri 以向 https://example.com/request/uri?param=1 发出请求。
【讨论】: