Delphi 用IdHTTP控件获取网页源码报错

zzw709 2010-07-26 09:34:16
代码如下:
try
v_Temp:=IdHTTP1.Get('http://www.google.com');
except
Showmessage('Error');
end;

抛异常为:
Project main.exe raised exception class EIdSocketError with message 'Socket Error # 10054
Connection reset by peer.'. Process stopped. Use Step or Run to continue.

不知道是什么原因造成的,有的时候可以,有的时候不行,不知道原因,请高手给出解释,谢谢
...全文
387 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mit1208 2010-07-27
  • 打赏
  • 举报
回复
没问题啊...
idhttp1.HandleRedirects :=True ;
memo1.Text :=IdHTTP1.Get('http://www.google.com') ;
mfpg01 2010-07-27
  • 打赏
  • 举报
回复
试试这个吧。

function GetWebPage (Url:string): string;
var
Session,
HttpFile:HINTERNET;
szSizeBuffer:Pointer;
dwLengthSizeBuffer:DWord;
dwReserved:DWord;
dwFileSize:DWord;
dwBytesRead:DWord;
Contents:PChar;
begin
Session:=InternetOpen('',0,niL,niL,0);
HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0);
dwLengthSizeBuffer:=1024;
HttpQueryInfo(HttpFile,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved);
GetMem(Contents,dwFileSize);
InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result:=StrPas(Contents);
FreeMem(Contents);
end;
mfpg01 2010-07-27
  • 打赏
  • 举报
回复
获得源码不稳定,有的版本可以,有的不可以。
cuit_xiong 2010-07-27
  • 打赏
  • 举报
回复
Get不是每个网站都行的,你换一个事实!
slmax1 2010-07-27
  • 打赏
  • 举报
回复
你换一个网址试试看
无条件为你 2010-07-27
  • 打赏
  • 举报
回复
获取源码的方式很多,你采用的是最差的一种方法。不稳定。
你加分后我给你贴出其它方法。
nkym0626 2010-07-27
  • 打赏
  • 举报
回复
百度有时候也出这样的错误
Frank.WU 2010-07-26
  • 打赏
  • 举报
回复
根据代码 #10054 代码去官网查FAQ

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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