老子横刀向天笑
2015-01-09 09:28
采纳率: 66.7%
浏览 1.8k
已采纳

delphi调用HttpQueryInfo函数编译报错,说参数类型不符合

procedure Get(url,heads: string;res: TStream);
var
  hInt,hUrl:HINTERNET;
  buffer:PChar;
  dwRead:cardinal;
  hBuf:PChar;
  flag:Boolean;
  len,index:Integer;
  var value: DWORD;
begin
 GetMem(buffer, 65536);
 GetMem(hBuf, 65536);
 hInt := InternetOpen('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
 dwRead:=0;
 if Trim(heads)<>'' then
    hurl:=InternetOpenUrl(hInt,PChar(url),PAnsiChar(AnsiString(heads)),Length(AnsiString(heads)),INTERNET_FLAG_RELOAD,0)
 else
    hurl:=InternetOpenUrl(hInt,PChar(url),nil,0,INTERNET_FLAG_RELOAD,0);
 //获取响应头信息
 flag:=HttpQueryInfo(hurl,HTTP_QUERY_RAW_HEADERS_CRLF,hBuf,len,index);
 //showmessage(StrPas(hBuf));

 repeat
   InternetReadFile(hUrl,buffer,1000,dwRead);
   if dwRead<>0 then
     res.Write(buffer^, dwRead);
 until dwRead=0;
 InternetCloseHandle(hUrl);
 InternetCloseHandle(hInt);
 FreeMem(buffer);
end; 

报错是从len参数开始报错的,我看了函数,最后两个参数是var的,我试着传过地址也不行,我看网上有人跟我一样的就行就我的不行,有谁搞过,请多多指教!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • pathletboy 2015-01-10 14:22
    已采纳

    局部变量定义
    len,index:integer;
    修改为
    len,index:Cardinal;

    打赏 评论

相关推荐 更多相似问题