多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 请求帮助 Slim’s PSR-7 Request implementation provides these additional proprietary methods to help you further inspect the HTTP request. > Slim的PSR-7请求实现提供了这些额外的专有方法来帮助您进一步检查HTTP请求。 ## Detect XHR requests 检测XHR请求 You can detect XHR requests by checking if the header`X-Requested-With`is`XMLHttpRequest`using the Request’s`getHeaderLine()`method. > 您可以通过使用请求的 **getHeaderLine()** 方法检查标题`X-Requested-With`是否为`XMLHttpRequest`来检测XHR请求。 ~~~bash POST /path HTTP/1.1 Host: example.com Content-type: application/x-www-form-urlencoded Content-length: 7 X-Requested-With: XMLHttpRequest foo=bar ~~~ Figure 13: Example XHR request. ~~~php if ($request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest') { // Do something } ~~~ ## Content Type You can fetch the HTTP request content type with the Request object’s`getHeaderLine()`method. > 您可以使用请求对象的 **getHeaderLine()** 方法获取HTTP请求内容类型。 ~~~php $contentType = $request->getHeaderLine('Content-Type'); ~~~ ## Content Length You can fetch the HTTP request content length with the Request object’s`getHeaderLine()`method. > 您可以使用请求对象的 **getHeaderLine()** 方法获取HTTP请求内容长度。 ~~~php $length = $request->getHeaderLine('Content-Length'); ~~~ ## Request Parameter To fetch single request parameter value. You will need to use `getServerParams()` > 获取单个请求参数值。您将需要使用 **getServerParams()** For example, to get a single Server Parameter: ~~~php $params = $request->getServerParams(); $authorization = isset($params['HTTP_AUTHORIZATION']) : $params['HTTP_AUTHORIZATION'] : null; ~~~