function GetRedirection(
const Url:
string):
string;
var
hInet: HINTERNET;
hConnect: HINTERNET;
infoBuffer:
array [0..512]
of char;
dummy: DWORD;
bufLen: DWORD;
okay: longbool;
reply:
string;
begin
Result := '
?';
hInet := InternetOpen(PChar('
a browser...'), INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil, 0);
hConnect := InternetOpenUrl(hInet, PChar(
Url),
nil, 0, INTERNET_FLAG_RELOAD +
INTERNET_FLAG_NO_AUTO_REDIRECT, 0);
if not Assigned(hConnect)
then
Exit
else
begin
dummy := 0;
bufLen := Length(infoBuffer);
okay := HttpQueryInfo(hConnect, HTTP_QUERY_STATUS_CODE,
@infoBuffer[0], bufLen, dummy);
if not okay
then
Exit
else
begin
reply := infoBuffer;
if (reply = '
301')
or (reply = '
302')
then
begin
dummy := 0;
bufLen := Length(infoBuffer);
okay := HttpQueryInfo(hConnect, HTTP_QUERY_LOCATION,
@infoBuffer[0], bufLen, dummy);
if not okay
then
Exit
else
begin
reply := infoBuffer;
if reply <> '
'
then
Result := reply;
end;
end
else
Exit;
end;
InternetCloseHandle(hConnect);
end;
InternetCloseHandle(hInet);
end;