Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Размер файла в сети [D7, XP]


HF-Trade ©   (2008-04-14 02:56:00) 

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

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

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');
......


HF-Trade   (2008-04-16 19:16:00) [1]


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

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


ЦУП   (2008-04-16 02:21:00) [2]


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


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


&lt;&gt;   (2008-04-16 00:21:00) [3]

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


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;


HF-Trade   (2008-04-15 20:10:00) [4]

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


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


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


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


HF-Trade   (2008-04-15 02:05:00) [6]

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


MetalFan   (2008-04-14 23:18:00) [7]

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


HF-Trade   (2008-04-14 19:59:00) [8]

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


HF-Trade   (2008-04-14 19:57:00) [9]

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');


&lt;&gt;   (2008-04-14 19:25:00) [10]

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

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:02:00) [11]

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


&lt;&gt;   (2008-04-14 11:43:00) [12]

> 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.


Наверх

Титульная страница Поиск, карта сайта Написать письмо