[英]How to ensure that my response from server has `Content-Length` header with PHP?
這是我從服務器響應的方式:
include('../connection.php');
connection();
mysql_query('SET NAMES utf8');
$response = array();
$words = array();
$query = "SELECT * FROM `$table` ORDER BY `created_at` DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$row['id'] = intval($row['id']);
array_push($words, $row);
}
$response['words'] = $words;
echo json_encode($response);
但是我這里確實需要Content-Length
標頭。 如何檢查或添加/創建此類標題?
如果您啟用輸出自助餐,PHP會為您處理。 當您通過緩沖區寫入輸出流時,PHP知道您已寫入多少內容,並在發送響應正文之前設置標頭值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.