<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 響應頭 Every HTTP response has headers. These are metadata that describe the HTTP response but are not visible in the response’s body. The PSR-7 Response object provides several methods to inspect and manipulate its headers. > 每個HTTP響應都有標頭。這些元數據描述了HTTP響應,但在響應體中不可見。PSR-7響應對象提供了幾個方法來檢查和操作它的標頭。 ## 獲取所有響應頭 getHeaders You can fetch all HTTP response headers as an associative array with the PSR-7 Response object’s`getHeaders()`method. The resultant associative array’s keys are the header names and its values are themselves a numeric array of string values for their respective header name. > 您可以使用PSR-7響應對象的`getHeaders()`方法以關聯數組的形式獲取所有的HTTP響應報頭。由此產生的關聯數組的鍵是標題名,其值本身是各自標題名的字符串值的數字數組。 ~~~php $headers = $response->getHeaders(); foreach ($headers as $name => $values) { echo $name . ": " . implode(", ", $values); } ~~~ Figure 5: Fetch and iterate all HTTP response headers as an associative array. ## 獲取其中一個響應頭 getHeader You can get a single header’s value(s) with the PSR-7 Response object’s`getHeader($name)`method. This returns an array of values for the given header name. Remember,*a single HTTP header may have more than one value!* > 您可以使用PSR-7響應對象的`getHeader($name)`方法獲得單個標題的值。這將返回給定標題名稱的值數組。記住,*一個HTTP報頭可能有多個值!* ~~~php $headerValueArray = $response->getHeader('Vary'); ~~~ Figure 6: Get values for a specific HTTP header. You may also fetch a comma-separated string with all values for a given header with the PSR-7 Response object’s`getHeaderLine($name)`method. Unlike the`getHeader($name)`method, this method returns a comma-separated string. > 您還可以使用PSR-7響應對象的`getHeaderLine($name)`方法獲取一個以逗號分隔的字符串,其中包含給定標題的所有值。與`getHeader($name)`方法不同,該方法返回一個逗號分隔的字符串。 ~~~php $headerValueString = $response->getHeaderLine('Vary'); ~~~ Figure 7: Get single header's values as comma-separated string. ## 檢測響應頭 hasHeader You can test for the presence of a header with the PSR-7 Response object’s`hasHeader($name)`method. > 您可以使用PSR-7響應對象的`hasHeader($name)`方法測試報頭是否存在。 ~~~php if ($response->hasHeader('Vary')) { // Do something } ~~~ Figure 8: Detect presence of a specific HTTP header. ## 設置響應頭 withHeader You can set a header value with the PSR-7 Response object’s`withHeader($name, $value)`method. > 您可以使用PSR-7響應對象的`withHeader($name, $value)`方法設置標題值。 ~~~php $newResponse = $oldResponse->withHeader('Content-type', 'application/json'); ~~~ Figure 9: Set HTTP header **Reminder** The Response object is immutable. This method returns a*copy*of the Response object that has the new header value.**This method is destructive**, and it*replaces*existing header values already associated with the same header name. > 提醒 > Response對象是不可變的。此方法返回具有新標頭值的響應對象的**副本**。**這個方法是破壞性的**,它*替換*已經關聯到相同標題名的現有標題值。 ## 附加響應頭 withAddedHeader You can append a header value with the PSR-7 Response object’s`withAddedHeader($name, $value)`method. > 您可以使用PSR-7響應對象的`withAddedHeader($name, $value)`方法附加一個標題值。 ~~~php $newResponse = $oldResponse->withAddedHeader('Allow', 'PUT'); ~~~ Figure 10: Append HTTP header **Reminder** Unlike the`withHeader()`method, this method*appends*the new value to the set of values that already exist for the same header name. The Response object is immutable. This method returns a*copy*of the Response object that has the appended header value. > 提醒 > > 與` withHeader()`方法不同,此方法*將*新值附加到已經存在的同一標題名稱的值集。Response對象是不可變的。此方法返回具有附加頭值的響應對象的副本。 ## 移除響應頭 withoutHeader You can remove a header with the Response object’s`withoutHeader($name)`method. > 您可以使用響應對象的`withoutHeader($name)`方法刪除標題。 ~~~php $newResponse = $oldResponse->withoutHeader('Allow'); ~~~ Figure 11: Remove HTTP header **Reminder** The Response object is immutable. This method returns a*copy*of the Response object that has the appended header value. > 提醒 > > Response對象是不可變的。此方法返回具有附加頭值的響應對象的副本。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看