我完全失去了这个问题。非常长的json响应停止并发送HTTP头文件,然后继续
我有一个ajax查询,它得到一个JSON响应。查询在大多数情况下都能正常工作,但是当json响应非常大时似乎很失败。
问题是响应的形式结束:
...est":"test length"}]]}
HTTP/1.1 200 OK
Date: Wed, 21 Sep 2011 17:10:32 GMT
Server: Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By: PHP/5.3.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=90
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
5b03d
{"ResultsInfo":{"RequestID":"131661886010","FeedCompletion":{"0":"100"}},"ResultsData":[[{"test":"test length"},{"test":"test length"},
...0
该...表示多个相同的“{”测试“:”测试长度“}的,”串
所以的效应初探似乎是以下形式:
- 最后数据
- HTTP响应报头在主体打印出的部分 个
- 字符“5b03d”
- 的数据的第一部分
- 字符“0”
没有响应的精确长度,这发生在但它是在360791个字符,但不精在372797个字符。
我使用的Yii PHP框架,但搜索范围很广,没有看到任何有论坛的东西。
在我看来,网络服务器将响应分成几块或超时并重新开始。
或者也许有最大的回报大小?
编辑 _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ ___
我尝试过应用程序/ json内容类型的建议,但它是stil发生。即在人体中返回的标头的TES文本部分是(使用applciaiton时/ JSON编码)如下:
HTTP/1.1 200 OK
Date: Thu, 22 Sep 2011 08:48:28 GMT
Server: Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By: PHP/5.3.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=89
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json
如何关闭分块编码为这个特殊的脚本?
**编辑2_8 _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _
我现在已经增加了一个内容长度我的头和响应报头,我得到的身体还在打印出来:
HTTP/1.1 200 OK
Date: Thu, 22 Sep 2011 11:55:39 GMT
Server: Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By: PHP/5.3.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 372797
Keep-Alive: timeout=5, max=90
Connection: Keep-Alive
Content-Type: application/json
所以看起来是分块不再被寄的。然而,同样的问题存在 - 响应有内容,然后打印出标题,然后更多的内容。
**现在唯一的区别是它没有响应中的'5b03d'或'0'字符。
EDIT_3_ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _
至于问这里是我的php代码的摘要
$dataArray = array(
'ResultsData'=>array(
array('test'=>'test length'),
array('test'=>'test length'),
array('test'=>'test length'),
...
));
$return = json_encode($dataArray);
header('Content-Length: '.strlen($return));
header('Content-type: application/json');
echo $return;
你的php代码是什么样的?这是非常不寻常的。 –