Načítanie stránky
Funkcia GetHTML overí, či zadaná strnánka existuje a vráti jej obsah.
uses WinInet; Function GetHTML(AUrl: string): string; var databuffer : array[0..4095] of char; ResStr : string; hSession, hfile, hRequest: hInternet; dwindex,dwcodelen,datalen,dwread,dwNumber: cardinal; dwcode : array[1..20] of char; res : pchar; Str : pchar; begin ResStr:=''; if pos('http://',lowercase(AUrl))=0 then AUrl:='http://'+AUrl; hSession:=InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); if assigned(hsession) then begin hfile:=InternetOpenUrl( hsession, pchar(AUrl), nil, 0, INTERNET_FLAG_RELOAD, 0); dwIndex := 0; dwCodeLen := 10; HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex); res := pchar(@dwcode); dwNumber := sizeof(databuffer)-1; if (res ='200') or (res ='302') then begin while (InternetReadfile(hfile, @databuffer, dwNumber, DwRead)) do begin if dwRead =0 then break; databuffer[dwread]:=#0; Str := pchar(@databuffer); resStr := resStr + Str; end; end else ResStr := 'Status:'+res; if assigned(hfile) then InternetCloseHandle(hfile); end; InternetCloseHandle(hsession); Result := resStr; end; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Text:=GetHTML('http://localhost/') end;
29.12.2007 o 22:35
eeej
pekna web ale aj clanocek
velmi to teraz pouzivam
THX (dakujem)