The TinyUrl free service convert a long URL to small url, which is useful for example to make twitter posts.
to use this service from delphi you must make a request to this link http://tinyurl.com/api-create.php?url=the_url_to_convert_goes_here and the response is the TinyUrl generated
check the sample code to get the response
program DelphiTinyUrl;
{$APPTYPE CONSOLE}
uses
WinInet,
SysUtils;
function GetTinyUrl(Url:string):string;
const
tinyurl = 'http://tinyurl.com/api-create.php?url=%s';
BuffSize = 2048;
var
hInter : HINTERNET;
UrlHandle: HINTERNET;
BytesRead: Cardinal;
Buffer : Pointer;
begin
Result:='';
hInter := InternetOpen('', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(hInter) then
begin
GetMem(Buffer,BuffSize);
try
UrlHandle := InternetOpenUrl(hInter, PChar(Format(tinyurl,[Url])), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
begin
InternetReadFile(UrlHandle, Buffer, BuffSize, BytesRead);
if BytesRead>0 then
SetString(Result, PAnsiChar(Buffer), BytesRead);
InternetCloseHandle(UrlHandle);
end;
finally
FreeMem(Buffer);
end;
InternetCloseHandle(hInter);
end
end;
begin
try
Writeln(GetTinyUrl('https://theroadtodelphi.wordpress.com/'));
Readln;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.
and the response is
November 28, 2010 at 2:18 pm
thanks.
Pingback: Tweets that mention Creating a TinyUrl from Delphi « The Road to Delphi – a Blog About Delphi Programming (mostly) -- Topsy.com
November 29, 2010 at 5:27 am
Hello.
It’s a usefull tip. Clear and simple.
Thanks.
Pingback: Sip from the Firehose : Developer Christmas Countdown - December 11 - T minus 14 days