Gimana ya caranya kalau mau cek apakah suatu URL (misal
http://www.coba.com/files/12345.exe ) itu ada / tidak.
Sebenarnya operasi-operasi ringan dengan HTTP di Windows bisa memakai
WinInet. Kebetulan saya pernah oprek, jadi kalo sekedar perintah ‘HEAD’ bisa seperti berikut.
uses WinInet;
function GetHttpStatus(Host, fileURL: string): Integer;
var
hSession, hConnect, hRequest: HInternet;
BufferLen, Dummy: Cardinal;
begin
Result := 0;
hSession := InternetOpen(nil, INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
if not Assigned(hSession) then RaiseLastOSError; {CMIIW}
hConnect := InternetConnect(hSession, PChar(Host), INTERNET_DEFAULT_HTTP_PORT,
nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
if Assigned(hConnect) then begin
hRequest := HttpOpenRequest(hConnect, ‘HEAD’, PChar(fileURL), ‘HTTP/1.0′,
nil, nil, INTERNET_FLAG_NO_COOKIES or INTERNET_FLAG_DONT_CACHE, 0);
if Assigned(hRequest) then try
HttpSendRequest(hRequest, nil, 0, nil, 0);
Dummy := 0; BufferLen := SizeOf(Result);
if not HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE or HTTP_QUERY_FLAG_NUMBER,
@Result, BufferLen, Dummy) then Result := HTTP_STATUS_BAD_REQUEST;
finally
InternetCloseHandle(hConnect);
end;
InternetCloseHandle(hRequest);
end;
InternetCloseHandle(hSession);
end;…
if GetHttpStatus(‘www.coba.com’, ‘/files/12345.exe’) <> 2xx then …
Parameter-parameter query, dan seterusnya, bisa dilihat di WinInet.Pas.
Kecret berkata
Mangstabsssss emank bro Mpu Gondrong …… BTW ga pernah ada KopDar Delphindo lagi nehh ???….