[英]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.