hSession := InternetOpen('
InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil, 0);
if assigned(hsession)
then
begin
repeat
hfile := InternetOpenUrl (hsession, PChar (
url),
nil, 0, INTERNET_FLAG_NO_AUTO_REDIRECT, 0);
{Get Validation}
Buflen := 512;
Dummy := 0;
HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @infoBuffer[0], Buflen, Dummy);
result := (infoBuffer ='
200')
or (infoBuffer ='
301')
or (infoBuffer ='
302');
if result
then
begin
{Get Link}
Buflen := sizeof(infoBuffer2);
Dummy := 0;
HttpQueryInfo(hfile, HTTP_QUERY_LOCATION, @infoBuffer2[0], Buflen, Dummy);
Str1 := infoBuffer2;
if Str1 =
url then Str1 := '
';
if Str1 <> '
'
then url := Str1;
End;
if assigned(hfile)
then InternetCloseHandle(hfile);
until (result = False)
OR (Str1 = '
');
InternetCloseHandle(hsession);
end;