Pythontr

husonet | Tarih: 17.10.2014

Delphi https 'ssl' sayfadan veri okunması

Delphi ile ssl sayfanın veri içeriğini okuyan fonksiyon.

İndy ile yapmaya çalıştığım google ssl sayfasından veri okuma işini çok daha pratik bir şekilde winnet ile yapan fonksiyonu paylaşıyorum.

uses WinInet;

GetUrlContent(sUrl: string): String;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1023] of byte;
BytesRead: dWord;
StrBuffer: UTF8String;
begin
Result := '';
NetHandle := InternetOpen('Delphi 2009', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
try
UrlHandle := InternetOpenUrl(NetHandle, PChar(sUrl), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
try
repeat
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
SetString(StrBuffer, PAnsiChar(@Buffer[0]), BytesRead);
Result := Result + StrBuffer;
until BytesRead = 0;
finally
InternetCloseHandle(UrlHandle);
end
else
raise Exception.CreateFmt('Cannot open URL %s', [sUrl]);
finally
InternetCloseHandle(NetHandle);
end
else
raise Exception.Create('Unable to initialize Wininet');
end;


Kullanımı ise
GetUrlContent(TIdURI.URLEncode('https://www.google.com'));


Kolay gelsin...