internetteki dosya boyutu

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Nemesis2005
Üye
Mesajlar: 136
Kayıt: 18 Oca 2005 05:24
Konum: İzmir

internetteki dosya boyutu

Mesaj gönderen Nemesis2005 »

internetteki dosya boyutunu bu fonksiyon ile öğreniyorum. ama şöyle bir problemim var arka arkaya aynı fonksiyonu çalıştırırsam program kitleniyor ikinci dosyanın boyutunu döndürmüyor sebep ne olabilir.

Kod: Tümünü seç

function TFrmGuncel.GetInetFileSize(const FileURL: string): Dword;
var
  hInternetSession, hInternetConnect, hHttpOpenRequest: HINTERNET;
  lpszAgent, lpszServerName, lpszObjectName, lpszReferrer, lplpszAcceptTypes: PChar;
  lpdwBufferLength, lpdwReserved: DWORD;
  lpvBuffer: array[0..1024] of Char;
begin
  lpszAgent := PChar(ExtractFileName(Application.ExeName));
  lpszServerName := PChar(GetParsedURL(FileURL, 0));
  lpszObjectName := PChar(GetParsedURL(FileURL, 1));
  lpszReferrer := PChar('');
  lplpszAcceptTypes := PChar('Accept: */*');
  lpdwBufferLength := 1024;
  lpdwReserved := 0;

  try
    hInternetSession := InternetOpen(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
    try
      hInternetConnect := InternetConnect(hInternetSession, lpszServerName, INTERNET_DEFAULT_HTTP_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
      hHttpOpenRequest := HttpOpenRequest(hInternetConnect, 'HEAD', lpszObjectName, 'HTTP/1.1', lpszReferrer, @lplpszAcceptTypes, INTERNET_FLAG_RELOAD, 0);
      HttpSendRequest(hHttpOpenRequest, nil, 0, nil, 0);
      HttpQueryInfo(hHttpOpenRequest, HTTP_QUERY_CONTENT_LENGTH, @lpvBuffer, lpdwBufferLength, lpdwReserved);

      if lpdwBufferLength > 0 then
      begin
        Result := StrToInt(Copy(lpvBuffer, 1, lpdwBufferLength));
      end
      else
      begin
        Result := 0;
      end;
    except
      Result := 0;
    end;
  except
    Result := 0;
  end;

  if hInternetSession <> nil then
  begin
    InternetCloseHandle(hInternetSession);
  end;
end;
Her iyinin içinde bir Kötülük.Her Kötnün içide de bir iyilik vardır
cagatay77
Üye
Mesajlar: 37
Kayıt: 31 Eki 2003 12:34

Mesaj gönderen cagatay77 »

Bu fonksiyon yerine şu kodu bir dene. Sorununu giderebilir diye düşünüyorum.

Kod: Tümünü seç

idHTTP1.Head('dosya adresi');
boyut:=idHTTP1.Response.ContentLength;
iyi çalışmalar...
Cevapla