H
hs-kill
Unregistered / Unconfirmed
GUEST, unregistred user!
我用HttpQueryInfo获取网上一个文件的大小,语句如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,wininet;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
hconnect,hSession,hService: HINTERNET;
RetQueryInfo:boolean;
AcceptTypes,
urlheaderchar;
bufferchar;
r,hWORD;
dwBytesRead: DWORD;
begin
AcceptTypes:='*/*';
urlheader:=pchar('Content-Type: application/octet-stream'+#10+#13+#10+#13+'accept-encoding:gzip, deflate'+#10+#13+#10+#13+'Range: bytes=0-'+#10+#13+#10+#13);
hSession:= InternetOpen('VRDownLoad', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
if Assigned(hSession) then
begin
hconnect:=InternetConnect(hsession,'www2.haoyisheng.com.cn',80,nil,nil,INTERNET_SERVICE_HTTP,0,0);
hService:=HttpOpenRequest(hconnect,'GET','/im/god.jpg','HTTP/1.1',nil,@AcceptTypes,INTERNET_FLAG_RELOAD,0);
if Assigned(hService) then
begin
HttpSendRequest(hService,urlheader,length(urlheader),nil,0);
r:=255;
h:=0;
RetQueryInfo:=HttpQueryInfo(hService,HTTP_QUERY_CONTENT_LENGTH ,Buffer,r,h);
{ if RetQueryInfo then
form1.Caption:=copy(buffer,0,r);}
end;
end;
finally
InternetCloseHandle(hService);
InternetCloseHandle(hconnect);
InternetCloseHandle(hSession);
end;
end;
end.
能正常取得大小,问题是取得后过一会就会出现一个user32.dll的内存读取错误
(不知道为什么,我如果在上面那句话设了断点,单部执行就会出错,如果不设断点,执行完不会出错,可是如果执行application的任何方法都会出现这个错误,而且除非关闭窗口,否则一直出现)
我看了很多大富翁离线数据里的东西,都是这么写啊。。郁闷
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,wininet;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
hconnect,hSession,hService: HINTERNET;
RetQueryInfo:boolean;
AcceptTypes,
urlheaderchar;
bufferchar;
r,hWORD;
dwBytesRead: DWORD;
begin
AcceptTypes:='*/*';
urlheader:=pchar('Content-Type: application/octet-stream'+#10+#13+#10+#13+'accept-encoding:gzip, deflate'+#10+#13+#10+#13+'Range: bytes=0-'+#10+#13+#10+#13);
hSession:= InternetOpen('VRDownLoad', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
if Assigned(hSession) then
begin
hconnect:=InternetConnect(hsession,'www2.haoyisheng.com.cn',80,nil,nil,INTERNET_SERVICE_HTTP,0,0);
hService:=HttpOpenRequest(hconnect,'GET','/im/god.jpg','HTTP/1.1',nil,@AcceptTypes,INTERNET_FLAG_RELOAD,0);
if Assigned(hService) then
begin
HttpSendRequest(hService,urlheader,length(urlheader),nil,0);
r:=255;
h:=0;
RetQueryInfo:=HttpQueryInfo(hService,HTTP_QUERY_CONTENT_LENGTH ,Buffer,r,h);
{ if RetQueryInfo then
form1.Caption:=copy(buffer,0,r);}
end;
end;
finally
InternetCloseHandle(hService);
InternetCloseHandle(hconnect);
InternetCloseHandle(hSession);
end;
end;
end.
能正常取得大小,问题是取得后过一会就会出现一个user32.dll的内存读取错误
(不知道为什么,我如果在上面那句话设了断点,单部执行就会出错,如果不设断点,执行完不会出错,可是如果执行application的任何方法都会出现这个错误,而且除非关闭窗口,否则一直出现)
我看了很多大富翁离线数据里的东西,都是这么写啊。。郁闷