Subject:
小弟又遇到问题了 各位哥哥帮忙看一下吧 :-)
[Print This Page]
Author:
精灵猪
Time:
2007-7-21 00:31
Subject:
小弟又遇到问题了 各位哥哥帮忙看一下吧 :-)
比如网站上有一个文本 [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]]
Author:
skyjacker
Time:
2007-7-21 09:59
szSizeBuffer
dwFileSize
不初始化会不稳定.
Author:
精灵猪
Time:
2007-7-21 19:52
请教skyjacker 大哥应该如何修改 难道对他们赋个初始值就可以了吗?
Author:
skyjacker
Time:
2007-7-21 23:31
Subject:
是啊。
function GetWebPage(const Url: string):string;
var
Session,
HttpFile:HINTERNET;
szSizeBuffer: array [0..1023] of char;// szSizeBuffer
ointer;
dwLengthSizeBuffer
Word;
dwReserved
Word;
dwFileSize
Word;
dwBytesRead:DWord;
Contents
Char;
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;
Author:
精灵猪
Time:
2007-7-22 12:37
多谢谢skyjacker 大哥的指点
Author:
zzzl
Time:
2007-8-2 22:16
来晚了
Author:
Rainstorey
Time:
2007-8-3 10:57
用Socket发送Http请求协议即可
Welcome to CnPack Forum (http://bbs.cnpack.org/)
Powered by Discuz! 5.0.0