当IdHttp遇上Transfer-Encoding: chunked

Bosman 2011-04-02 07:49:01
C++ Buider 2009

用idhttp Post一个表单,比如:

try
{
dt=(double)Now();//dt为double型
Http->Post(PostWeb,PostParam,HttpStream);
t=((double)Now()-dt)*86400000;
MainForm->MemoInfo->Lines->Add(FloatToStr(t));//使用时间(毫秒) }
catch(Exception &e)
{
MainForm->MemoInfo->Lines->Add(Http->ResponseText+" "+e.Message);
return -2;
}
Post的内容很少.但Post后服务器返回Transfer-Encoding: chunked的编码内容.并且内容也很短,不到300字节.

idhttp似乎在处理返回Transfer-Encoding: chunked编码这方面内容特别慢.
以上测试基本都在5秒以上才返回.同一网站,如果不是返回Transfer-Encoding: chunked编码的,不用一秒就返回.

上网找过资料,idhttp遇到响应是Transfer-Encoding: chunked编码的,只有等服务器与自己连接关闭才返回.

以上测试如下:
开始Post
6:31:22 AM 状态=Disconnecting.
6:31:22 AM 状态=Disconnected.
6:31:22 AM 状态=Resolving hostname www.aa3ew.com.
6:31:22 AM 状态=Connecting to 63.220.135.26.
6:31:22 AM 状态=Connected.//连接上
6:31:27 AM 状态=Disconnected.//读Transfer-Encoding: chunked内容结束
4996.00048642606 //消耗时间差不多功能5秒,甚至更长..

我的问题是:idhttp遇上Transfer-Encoding: chunked,处理是不是有Bug??
或是有什么方法加快处理接收Transfer-Encoding: chunked 编码的内容,不用等到服务器与idhttp关闭连接才返回.
...全文
361 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bosman 2011-04-07
  • 打赏
  • 举报
回复
代码我也看过.
idhttp执行时,有时是返回超时,实在上已post成功.有时post不成功,但返回404错误.
My_Love 2011-04-07
  • 打赏
  • 举报
回复
{但从Indy的代码来看,与上面协议显然不一致。}
begin
if AResponseContent <> nil then
begin
if Response.ContentLength <> 0 then
begin
ReadStream(AResponseContent, Response.ContentLength);
end
else
begin
if AnsiPos('chunked', Response.ExtraHeaders.Values['Transfer-Encoding'])
> 0 then {do not localize}
begin
DoStatus(hsText, [RSHTTPChunkStarted]);
Size := ChunkSize;
while Size > 0 do
begin
ReadStream(AResponseContent, Size);
ReadLn;
Size := ChunkSize;
end;
ReadLn;
end
else
begin
ReadStream(AResponseContent, -1, True);
end;
end;
end;
end;
My_Love 2011-04-07
  • 打赏
  • 举报
回复
只找到这一个理解HTTP协议中的"Transfer-Encoding: chunked",不知LZ是否看过。
Bosman 2011-04-04
  • 打赏
  • 举报
回复
Added TIdEventStream class. Primarily for use with TIdHTTP when dealing with chunked responses that are endless.
jone7319 2011-04-02
  • 打赏
  • 举报
回复
帮你顶一下,我是自己写个类来完成的,Indy的组件有时会遇到一些莫名其妙的问题
Bosman 2011-04-02
  • 打赏
  • 举报
回复
老妖啊..你快来啊.

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧