这就是我从服务器的响应方式:
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知道您写了多少,并在发送响应体之前设置头值。