Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2008.05.18;
Скачать: CL | DM;

Вниз

Размер файла в сети   Найти похожие ветки 

 
HF-Trade ©   (2008-04-14 02:56) [0]

Здраствуйте.
Вопросик вообщем то, наверное не новый=)
Да, видимо я туповатый=)

-
В инете обшарил гору форумов, как определить размер файла в сети, использую данную функцию(ниже), собсно почему она не арбайтен?

function GetUrlInfo(const dwInfoLevel: DWORD; const FileURL: string):
string;
var
 hSession, hFile: hInternet;
 dwBuffer: Pointer;
 dwBufferLen, dwIndex: DWORD;
begin
 Result := "";
 hSession := InternetOpen("xxx",                           INTERNET_OPEN_TYPE_PRECONFIG {PRE_CONFIG_INTERNET_ACCESS}, nil, nil, 0);
 if Assigned(hSession) then begin
   hFile := InternetOpenURL(hSession, PChar(FileURL), nil, 0,
                            {INTERNET_FLAG_RELOAD}0, 0);
   dwIndex  := 0;
   dwBufferLen := 20;
   if HttpQueryInfo(hFile, dwInfoLevel, @dwBuffer, dwBufferLen, dwIndex)
     then Result := PChar(@dwBuffer);
   if Assigned(hFile) then InternetCloseHandle(hFile);
   InternetCloseHandle(hsession);
 end;
end;

.....
Для примера файл весящий 17+ мб.
(Размер файлов небольшого размера ~до 200кб определяеться нормально, но вот выше...).
......
Caption:=GetUrlInfo(HTTP_QUERY_CONTENT_LENGTH, "http://files.3dnews.ru/pub/soft/multimedia/codec/klmcodec385.exe");
......


 
<>   (2008-04-14 11:43) [1]

> dwBuffer: Pointer;

Указатель есть, а буфера нет:
http://msdn2.microsoft.com/en-us/library/aa384238(VS.85).aspx

lpvBuffer

Pointer to a buffer to receive the requested information. This parameter must not be NULL.


 
HF-Trade ©   (2008-04-14 19:02) [2]

dwBuffer: Pointer;
взято от сюда...
http://icoder.ru/pages/new1s5o497960.html


 
<>   (2008-04-14 19:25) [3]

У меня работает:

uses Wininet;

function GetUrlInfo(const dwInfoLevel: DWORD; const FileURL: string):
string;
var
   hSession, hFile: hInternet;
   dwBuffer: Pointer;
   dwBufferLen, dwIndex: DWORD;
   db:Array[1..512] of char;
begin
   dwBuffer:=@db[1];
   Result := "";
   hSession := InternetOpen(PChar(Application.Title),{INTERNET_OPEN_TYPE_PRECONFIG} PRE_CONFIG_INTERNET_ACCESS, nil, nil, 0);
   if Assigned(hSession) then begin
   hFile := InternetOpenURL(hSession, PChar(FileURL), nil, 0,    {INTERNET_FLAG_RELOAD}0, 0);
   dwIndex := 0;
   dwBufferLen := 512;
   if HttpQueryInfo(hFile, dwInfoLevel, @dwBuffer, dwBufferLen, dwIndex)
   then Result := PChar(@dwBuffer);
   if Assigned(hFile) then InternetCloseHandle(hFile);
   InternetCloseHandle(hsession);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Caption:=GetUrlInfo(HTTP_QUERY_CONTENT_LENGTH, "http://files.3dnews.ru/pub/soft/multimedia/codec/klmcodec385.exe");
end;

Результат:18286263

В Интернет-Эксплорере нужно выключить автономный режим!


 
HF-Trade ©   (2008-04-14 19:57) [4]

dwBuffer: Pointer;
db:Array[1..512] of char;

мб проще -
dwBuffer:Array[0..20] of Char;

и все равно с другими ссылками траблы - например -
Caption:=GetUrlInfo(HTTP_QUERY_CONTENT_LENGTH, "http://www.gladiatorcom.nm.ru/UORecall.rar");


 
HF-Trade ©   (2008-04-14 19:59) [5]

Упс...
как получить размер файла с редиректом...
Вроде правильно сказал?=)


 
MetalFan ©   (2008-04-14 23:18) [6]

а там нет редиректа. там просто страничка с сылкой на сам файл.


 
HF-Trade ©   (2008-04-15 02:05) [7]

Ну, а как нить обойти это можно?


 
Оригинал   (2008-04-15 13:07) [8]


> HF-Trade ©   (15.04.08 02:05) [7]
> Ну, а как нить обойти это можно?


Использовать правильную ссылку?


 
HF-Trade ©   (2008-04-15 20:10) [9]

Так ссылка то прямая вроде - именно на файл.


 
<>   (2008-04-16 00:21) [10]

Нужно вставить реферер:


uses Wininet;

function GetUrlInfo(const dwInfoLevel: DWORD; const FileURL: string;head: string):
string;
var
  hSession, hFile: hInternet;
  dwBufferLen, dwIndex: DWORD;
  db:Array[1..512] of char;
begin
  Result := "";
  hSession := InternetOpen(PChar(Application.Title),{INTERNET_OPEN_TYPE_PRECONFIG} PRE_CONFIG_INTERNET_ACCESS, nil, nil, 0);
  if Assigned(hSession) then begin
  hFile := InternetOpenURL(hSession, PChar(FileURL), PChar(head), Length(head),    {INTERNET_FLAG_RELOAD}0, 0);
  dwIndex := 0;
  dwBufferLen := 512;
  if HttpQueryInfo(hFile, dwInfoLevel, @db, dwBufferLen, dwIndex)
  then Result := PChar(@db);
  if Assigned(hFile) then InternetCloseHandle(hFile);
  InternetCloseHandle(hsession);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Caption:=GetUrlInfo(HTTP_QUERY_CONTENT_LENGTH, "http://www.gladiatorcom.nm.ru/UORecall.rar",
"referer: http://www.gladiatorcom.nm.ru"+#13#10#13#10);
end;



 
ЦУП ©   (2008-04-16 02:21) [11]


> HF-Trade ©   (15.04.08 20:10) [9]
> Так ссылка то прямая вроде - именно на файл.


Какая же прямая.


 
HF-Trade ©   (2008-04-16 19:16) [12]


> <>   (16.04.08 00:21) [10]
> Нужно вставить реферер:

Огромное спасибо.



Страницы: 1 вся ветка

Текущий архив: 2008.05.18;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.024 c
15-1207310566
Биржа
2008-04-04 16:02
2008.05.18
CMS


15-1207136742
lead-in
2008-04-02 15:45
2008.05.18
dell


15-1207119287
Ega23
2008-04-02 10:54
2008.05.18
А вот как сделано: регистрируешься на каком-нибудь сайте,


2-1208498832
kudatsky
2008-04-18 10:07
2008.05.18
Не создаётся индекс в DBF-файле


3-1197297073
Fregl
2007-12-10 17:31
2008.05.18
Ошибка добавления lookup поля в TADOTable