# 請求幫助
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;
~~~
- 開始
- 安裝
- 升級指南
- Web服務器
- 概念
- 生命周期
- PSR 7
- 中間件
- 依賴容器
- 實例 及通知和警告處理
- Request
- 請求方法
- 請求頭信息
- 請求主體
- 上傳的文件
- 請求幫助
- 路由對象
- Response
- 響應狀態
- 響應標頭
- 響應體
- 返回JSON
- 視圖模板
- 路由
- 創建路由
- 路由回調
- 路由策略
- 路線占位符
- 路由名
- 路由組
- 路由中間件
- 路由表達式緩存
- 容器識別解析
- 封裝中間件
- 路由的中間件
- 錯誤處理中間件
- 方法重寫的中間件
- 輸出緩沖中間件
- 內容長度中間件
- 擴展功能
- 以 / 結尾的路由模式
- 獲取當前路由
- 設置CORS
- 使用POST表單上傳文件
- 第三方組件
- slim-session
- auth
- slim-api-skeleton
- dir