HttpQueryInfo的问题。。郁闷死了 ( 积分: 20 )

  • 主题发起人 主题发起人 hs-kill
  • 开始时间 开始时间
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,
urlheader:pchar;
buffer:pchar;
r,h:DWORD;
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的任何方法都会出现这个错误,而且除非关闭窗口,否则一直出现)

我看了很多大富翁离线数据里的东西,都是这么写啊。。郁闷
 
我用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,
urlheader:pchar;
buffer:pchar;
r,h:DWORD;
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的任何方法都会出现这个错误,而且除非关闭窗口,否则一直出现)

我看了很多大富翁离线数据里的东西,都是这么写啊。。郁闷
 
RetQueryInfo:=HttpQueryInfo(hService,HTTP_QUERY_CONTENT_LENGTH ,Buffer,r,h);
就是这句的问题。只要把这句话注释掉,或者返回值为false就没事。。。

而且如果把buffer类型换为dword也不会出错,可是取出来的值似乎就变成内存值了。。我不知道那样怎样获得存到里面的文件大小

各位帮帮忙啊。。。。。
 
没人知道吗???帮帮忙啊~~~~~
 
.............晕 还是我自己来解?
我现在把buf换成word类型的。。。然后获取信息的话换成:
RetQueryInfo:=HttpQueryInfo(hService,[red]HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER [/red],@Buf,lbuf,x);
这样取出来的buf就是正确的大小了

可是为什么要加个 or HTTP_QUERY_FLAG_NUMBER 才行呢?HTTP_QUERY_FLAG_NUMBER是什么标记啊?
 
........居然没人知道?
 
.......还是没人啊
 
后退
顶部