大家好。
我使用InternetQueryDataAvailable函数,得到的大小老是不对。代码如下:
hSession := InternetOpen('Delphi', 0, nil, nil, 0);
hConnection := InternetOpenURL(hSession, 'http://www.yahoo.com', nil, 0, 0, 0);
bResult := InternetQueryDataAvailable(hConnection, Size, 0, 0);如果改为使用
bResult := HttpQueryInfo(hConnection, HTTP_QUERY_CONTENT_LENGTH, @Buffer, iRead, iCount);却又返回ERROR_HTTP_HEADER_NOT_FOUND 错误, 太郁闷了。
麻烦大家帮忙看一下。一定给分。

解决方案 »

  1.   

    HttpQueryInfo(FhRequest, HTTP_QUERY_CONTENT_LENGTH,  @Buffer[0], BufLen,  dwIndex);
      

  2.   

    function TForm1.Deltree (path : string): Boolean ;
      var
       SearchRec: TSearchRec;
      begin
      //判断目录是否存在
    if DirectoryExists(path) then
    begin
      //进入该目录,删除其中的子目录和文件
       oldDir := GetCurrentDir;
       ChDir(path);
      //查找目录中所有任何文件
      FindFirst(′.′, faAnyFile, SearchRec);
      repeat
      //修改文件属性为普通属性值
       FileSetAttr(SearchRec.Name,0);
      //如果是目录并且不是.和..则递归调用DelTree
      if(SearchRec.Attr and faDirectory > 0) then
      begin
      if(SearchRec.Name[1]<>′.′) then
      if(not Deltree(SearchRec.Name)) then
      break;
      end
      //如果是文件直接删除
      else
      if(not DeleteFile(SearchRec.Name))then
      break ;
      //继续查找,直到最后
      until (FindNext(SearchRec)<>0) ;
      //回到父目录,删除该目录
      ChDir(′..′);
      Result := ReMoveDir(path);
    SetCurrentDir(oldDir);
      end
    else
      Result := False ;
      end ;
      该程序在Windows 98、Delphi 4.0下编译通过
      

  3.   

    langfei(浪费):@Buffer 和@Buffer[0]其实是一样的,问题不在这里。因为我并不是所有的URL都有问题,只是有些网址,例如www.yahoo.com, www.hp.com...对于HttpQueryInfo 函数,MSDN中给出这样的定义:
    BOOL HttpQueryInfo(
        IN HINTERNET hRequest,
        IN DWORD dwInfoLevel,
        IN LPVOID lpvBuffer,
        IN LPDWORD lpdwBufferLength,
        IN OUT LPDWORD lpdwIndex,
    );其中,lpdwIndex参数含义如下: 
    Address of a zero-based header index used to enumerate multiple headers with the same name. When calling the function, this parameter is the index of the specified header to return. When the function returns, this parameter is the index of the next header. If the next index cannot be found, ERROR_HTTP_HEADER_NOT_FOUND is returned. 我遇到的问题就是ERROR_HTTP_HEADER_NOT_FOUND错误,我不知道是什么原因。
      

  4.   

    高手们,真的没有人知道吗?如何获取Internet上的文件大小呢?
      

  5.   

    发送HTTP请求后,返回的信息中提取'Content-Length: '后的内容SendStr:=SendStr+'HEAD /'+FileName+' HTTP/1.0'+#13#10;
    SendStr:=SendStr+'Accept: */*'+#13#10;
    SendStr:=SendStr+'Host: '+Host+#13#10;
    SendStr:=SendStr+#13#10;
    ClientSocket.Socket.SendText(SendStr);
    while ClientSocket.Active do
    begin
      FStr:=TStringStream.Create('');
      FSocketStream:= TWinSocketStream.Create(ClientSocket, TimeoutInt);
      while ClientSocket.Connected do
      begin
        if not FSocketStream.WaitForData(TimeoutInt) then Break;
        ZeroMemory(@Buf,SizeOf(Buf));
        Res := FsocketStream.Read(Buf, 1);
        if Res=0 then break;
        FStr.Write(Buf,Res);
        if Pos(#13#10,FStr.DataString)<>0 then
        begin
          Break;
        end;
      end;
      CmdStr:=FStr.DataString;
      if Pos(LowerCase('Content-Length: '),LowerCase(CmdStr))=1 then
      begin
        ValueInt:=StrToInt(Copy(CmdStr,Length('Content-Length: ')+1,Length(CmdStr)));
      end;
    end;
      

  6.   

    不是所有情况都会返回文件大小,因为不是所有情况都是返回文件本身的内容,如cgi,dll,asp,php,jsp...这些文件实际上只是动态返回一些内容,所以是无法通过WEB方式获得文件大小的
      

  7.   

    谢谢ehorn的答复,我明白了。