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: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
| 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; |