1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Uses Wininet;
{----------------------------------------------------------------}
Function GetHTML(AUrl: String): String;
Var
databuffer: Array[0..4095] Of Char;
hSession, hfile: hInternet;
dwindex, dwcodelen, dwread, dwNumber: Cardinal;
dwcode: Array[1..20] Of Char;
res: PChar;
Begin
Result := '';
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;
Result := Result + PChar(@databuffer);
End;
End Else Result := 'Status:' + res;
If (Assigned(hfile)) Then InternetCloseHandle(hfile);
End;
InternetCloseHandle(hsession);
End;
{----------------------------------------------------------------}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
Memo1.Text := GetHTML('http://monsite.com/getmyip.php');
End; |
Partager