CnPack Forum


 
Subject: 小弟又遇到问题了 各位哥哥帮忙看一下吧 :-)
精灵猪
新警察
Rank: 1



UID 5299
Digest Posts 0
Credits 25
Posts 15
点点分 25
Reading Access 10
Registered 2007-2-3
Status Offline
Post at 2007-7-21 00:31  Profile | Blog | P.M. 
小弟又遇到问题了 各位哥哥帮忙看一下吧 :-)

比如网站上有一个文本 [url=http://www.163.com/111.txt[/url]www.163.com/111.txt[/url]内容为一行文本
我想写个程序获得上面的的这行文本 搞了半天没成功
结果在大富翁上看到了一个函数 是用Wininet单元实现的 虽然可以执行但是似乎有点问题 执行速度也不快 各位哥哥帮忙看看应该如何修改?
function GetWebPage(const 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;
这是这个函数

[[i] 本帖最后由 精灵猪 于 2007-7-21 00:32 编辑 [/i]]
Top
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-7-21 09:59  Profile | Blog | P.M.  | QQ
szSizeBuffer
dwFileSize
不初始化会不稳定.




一壶清茶煮青春.
Top
精灵猪
新警察
Rank: 1



UID 5299
Digest Posts 0
Credits 25
Posts 15
点点分 25
Reading Access 10
Registered 2007-2-3
Status Offline
Post at 2007-7-21 19:52  Profile | Blog | P.M. 
请教skyjacker 大哥应该如何修改 难道对他们赋个初始值就可以了吗?
Top
skyjacker
版主
Rank: 7Rank: 7Rank: 7
茶农


UID 2239
Digest Posts 9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
Post at 2007-7-21 23:31  Profile | Blog | P.M.  | QQ
是啊。

function GetWebPage(const Url: string):string;
var
  Session,
  HttpFile:HINTERNET;
  szSizeBuffer: array [0..1023] of char;// szSizeBufferointer;
  dwLengthSizeBufferWord;
  dwReservedWord;
  dwFileSizeWord;
  dwBytesRead:DWord;
  ContentsChar;
begin
  Session:=InternetOpen('',0,niL,niL,0);
  HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0);
  if not Assigned(HttpFile) then
    Exit;
  FillChar(szSizeBuffer, SizeOf(szSizeBuffer), #0); // HttpQueryInfo 缓冲区
  dwLengthSizeBuffer := SizeOf(szSizeBuffer);  //dwLengthSizeBuffer:=1024;
  dwReserved := 0;

  if not HttpQueryInfo(HttpFile,HTTP_QUERY_CONTENT_LENGTH,@szSizeBuffer[0],
    dwLengthSizeBuffer,dwReserved) then
    Exit;

  dwFileSize := StrToInt(szSizeBuffer); // 文件大小
  GetMem(Contents,dwFileSize);
  InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead);
  InternetCloseHandle(HttpFile);
  InternetCloseHandle(Session);
  Result:=StrPas(Contents);
  FreeMem(Contents);
end;




一壶清茶煮青春.
Top
精灵猪
新警察
Rank: 1



UID 5299
Digest Posts 0
Credits 25
Posts 15
点点分 25
Reading Access 10
Registered 2007-2-3
Status Offline
Post at 2007-7-22 12:37  Profile | Blog | P.M. 
多谢谢skyjacker 大哥的指点
Top
zzzl (早安的空气)
版主
Rank: 7Rank: 7Rank: 7



UID 590
Digest Posts 0
Credits 399
Posts 199
点点分 399
Reading Access 100
Registered 2004-11-29
Status Offline
Post at 2007-8-2 22:16  Profile | Blog | P.M.  | QQ
来晚了
Top
Rainstorey
普通灌水员
Rank: 2
菜鸟


UID 977
Digest Posts 0
Credits 82
Posts 39
点点分 82
Reading Access 10
Registered 2005-8-8
Location 苏州
Status Offline
Post at 2007-8-3 10:57  Profile | Blog | P.M. 
用Socket发送Http请求协议即可




Top
 




All times are GMT++8, the time now is 2024-11-23 17:04

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.009510 second(s), 9 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP