Вниз
Скачать: CL | DM;

<b>Получить html-файл с удаленного сервера</b>   Найти похожие ветки 

← →
Игорь   (2004-01-19 19:39) [0]

Вопрос такой. Как получить html-файл с удаленного сервера по заданному URL и сохранить его у себя на диске, не прибегая к использованию TWebBrawser? Заранее огромное спасибо.


← →
easy ©   (2004-01-20 16:25) [1]

uses wininet;

...

function DownloadFile(const Url: string): string;
var
 NetHandle: HINTERNET;
 UrlHandle: HINTERNET;
 Buffer: array[0..1024] of char;
 BytesRead: cardinal;
begin
 Result := "";
 NetHandle := InternetOpen("Delphi 5.x", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

 if Assigned(NetHandle) then
 begin

   UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);

   { UrlHandle правильный? Начинаем загрузку }
   if Assigned(UrlHandle) then
   begin
     FillChar(Buffer, SizeOf(Buffer), 0);
     repeat
       Result := Result + Buffer;
       FillChar(Buffer, SizeOf(Buffer), 0);
       InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
     until
       BytesRead = 0;
     InternetCloseHandle(UrlHandle);
   end
   else
   begin
     { UrlHandle неправильный. Генерируем исключительную ситуацию. }
     raise Exception.CreateFmt("Cannot open URL %s", [Url]);
   end;

   InternetCloseHandle(NetHandle);
 end
 else
   { NetHandle недопустимый. Генерируем исключительную ситуацию }
   raise Exception.Create("Unable to initialize Wininet");
end;



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

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.018 c
1-1078909890
MadGhost
2004-03-10 12:11
2004.03.28
как в функцию передать переменную по ссылке?


3-1077865464
Ega23
2004-02-27 10:04
2004.03.28
Ещё раз про настройки QA


3-1074854049
VolanD2002
2004-01-23 13:34
2004.03.28
Index is ReadOnly


1-1078835623
stelius
2004-03-09 15:33
2004.03.28
Tag &amp; Attribute XML


3-1077161106
GodHappy
2004-02-19 06:25
2004.03.28
ADOConnection




   Наверх