wininet 获得网页的源代码为什么在多线程里面获得不完全。function GetCode(const url: string): string;
var
hInet: HINTERNET;
hFile: HINTERNET;
buffer: array[1..1024] of char;
bytesRead: DWORD;
ta : Boolean;
begin
hInet := InternetOpen(PChar('Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)'),
INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
hFile := InternetOpenURL(hInet,PChar(url),nil,0,0,0);
if Assigned(hFile) then
begin
repeat
ta := InternetReadFile(hFile,@buffer,SizeOf(buffer),bytesRead);
result := result + Copy(buffer,1,bytesRead);
CnDebugger.LogMsg(Result); until (bytesRead = 0) and (ta = True) ;
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hInet);end;
如果只是测试这段代码,一点问题都没有,可以完全获得网页的源代码,
但是在我的程序中,这段代码,却总是获得不完全。
http://qqmlt.com/s.rar 这个是我的程序的元代码包,DELPHI7 哪位大侠有空帮我看看,
非常感谢。。
var
hInet: HINTERNET;
hFile: HINTERNET;
buffer: array[1..1024] of char;
bytesRead: DWORD;
ta : Boolean;
begin
hInet := InternetOpen(PChar('Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)'),
INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
hFile := InternetOpenURL(hInet,PChar(url),nil,0,0,0);
if Assigned(hFile) then
begin
repeat
ta := InternetReadFile(hFile,@buffer,SizeOf(buffer),bytesRead);
result := result + Copy(buffer,1,bytesRead);
CnDebugger.LogMsg(Result); until (bytesRead = 0) and (ta = True) ;
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hInet);end;
如果只是测试这段代码,一点问题都没有,可以完全获得网页的源代码,
但是在我的程序中,这段代码,却总是获得不完全。
http://qqmlt.com/s.rar 这个是我的程序的元代码包,DELPHI7 哪位大侠有空帮我看看,
非常感谢。。
感谢 acracker 测试,,,继续求解。
hInet: HINTERNET;
hFile: HINTERNET;
buffer: array[1..1024] of char;
bytesRead: DWORD;
begin
hInet := InternetOpen(PChar('Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0)'),
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); hFile := InternetOpenURL(hInet, PChar(url), nil, 0, 0, 0);
if Assigned(hFile) then
begin
repeat
InternetReadFile(hFile, @buffer, SizeOf(buffer), bytesRead);
result := result + Copy(buffer, 1, bytesRead);
until bytesRead = 0;
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hInet);
end;