Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
[solved] Obtain an expanded URL from tinyurl.com
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
How to prevent onDropFile...
by
cdbc
[
Today
at 03:09:19 pm]
The compiler fails to war...
by
AlexanderK
[
Today
at 02:59:21 pm]
Maze Makers: Now looking ...
by
Thaddy
[
Today
at 02:51:41 pm]
unit init, finalize and i...
by
Zvoni
[
Today
at 02:48:57 pm]
Embedded qss stylesheets ...
by
big_M
[
Today
at 01:01:30 pm]
Lazreport PDF
by
mig-31
[
Today
at 11:54:11 am]
Locate current record aft...
by
Zvoni
[
Today
at 09:59:08 am]
Drag and Drop Files; onDr...
by
Hansaplast
[
Today
at 09:39:25 am]
Lazarus and Libre Office
by
MarkMLl
[
Today
at 09:22:14 am]
Linked List Using Two Cla...
by
440bx
[
Today
at 08:56:54 am]
CudaText editor (written ...
by
AlexTP
[
Today
at 08:51:13 am]
scat bikes (inc)
by
speter
[
Today
at 04:38:11 am]
Effect of adding properti...
by
n7800
[
Today
at 04:13:36 am]
solution for installing F...
by
BradleySlavik
[
Today
at 02:37:22 am]
Lazarus seems to be makin...
by
n7800
[
Today
at 02:33:42 am]
What was your first compu...
by
CM630
[January 13, 2026, 10:09:19 pm]
Dragging files to .app no...
by
Boleeman
[January 13, 2026, 10:06:09 pm]
PngDrop: Reduce the size ...
by
Boleeman
[January 13, 2026, 09:50:19 pm]
Fantasy Worldbuilder; Pro...
by
Boleeman
[January 13, 2026, 09:45:56 pm]
TSpeedButton qt6 styleshe...
by
big_M
[January 13, 2026, 09:23:24 pm]
StrToDateTime problems
by
Nicole
[January 13, 2026, 07:45:13 pm]
How to forward a Class in...
by
Hartmut
[January 13, 2026, 07:41:31 pm]
Additional Filedialog opt...
by
Hansaplast
[January 13, 2026, 07:39:28 pm]
set zero values not to b...
by
wp
[January 13, 2026, 05:58:41 pm]
Fast Canvas Library V1.05...
by
Gigatron
[January 13, 2026, 05:15:06 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [solved] Obtain an expanded URL from tinyurl.com (Read 3504 times)
bobonwhidbey
Hero Member
Posts: 630
[solved] Obtain an expanded URL from tinyurl.com
«
on:
September 07, 2016, 05:15:11 am »
When I put this URL:
Code: HTML5
[Select]
[+]
[-]
http://tinyurl.com/jrs3grj
in my browser, the tinyurl.com website expands the URL to a very long URL and redirects my browser to open the large URL.
I use the following code to download an HTML file from the expanded URL.
Code: Pascal
[Select]
[+]
[-]
function
GetInternetFile
(
const
fileURL
,
FileName
:
string
)
:
boolean
;
const
BufferSize
=
1024
;
var
hSession
,
hURL
:
HInternet
;
Buffer
:
array
[
0
..
BufferSize
-
1
]
of
byte
;
BufferLen
:
DWORD
;
f
:
file
;
sAppName
:
string
;
MyTimeOut
,
Minutes
:
integer
;
begin
Minutes
:
=
10
;
myTimeOut
:
=
1000
*
60
*
Minutes
;
InternetSetOption
(
nil
,
INTERNET_OPTION_CONNECT_TIMEOUT
,
Pointer
(
@
myTimeOut
)
,
SizeOf
(
myTimeOut
)
)
;
InternetSetOption
(
nil
,
INTERNET_OPTION_SEND_TIMEOUT
,
Pointer
(
@
myTimeOut
)
,
SizeOf
(
myTimeOut
)
)
;
InternetSetOption
(
nil
,
INTERNET_OPTION_RECEIVE_TIMEOUT
,
Pointer
(
@
myTimeOut
)
,
SizeOf
(
myTimeOut
)
)
;
sAppName
:
=
ExtractFileName
(
Application
.
ExeName
)
;
hSession
:
=
InternetOpen
(
PChar
(
sAppName
)
,
INTERNET_OPEN_TYPE_PRECONFIG
,
nil
,
nil
,
0
)
;
try
hURL
:
=
InternetOpenURL
(
hSession
,
PChar
(
fileURL
)
,
nil
,
0
,
0
,
0
)
;
try
AssignFile
(
f
,
FileName
)
;
Rewrite
(
f
,
1
)
;
repeat
try
InternetReadFile
(
hURL
,
@
Buffer
,
SizeOf
(
Buffer
)
,
BufferLen
)
;
BlockWrite
(
f
,
Buffer
,
BufferLen
)
;
except
on E
:
EInOutError
do
begin
ShowMessage
(
'The '
+
IntToStr
(
Minutes
)
+
' minute maximum download time'
+
' has been exceded. Please try again at another time'
)
;
break
;
end
;
end
;
// except
until
BufferLen
=
0
;
CloseFile
(
f
)
;
Result
:
=
True
;
finally
InternetCloseHandle
(
hURL
)
end
finally
InternetCloseHandle
(
hSession
)
;
end
;
end
;
What I want to do is grab the expanded URL. It seems to me that it must exist in an hInternet Handle variable. Anyone know?
«
Last Edit: September 07, 2016, 03:38:55 pm by bobonwhidbey
»
Logged
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64
balazsszekely
Guest
Re: Obtain an expanded URL from tinyurl.com
«
Reply #1 on:
September 07, 2016, 05:39:08 am »
http://stackoverflow.com/questions/10707325/wininet-how-to-obtain-server-url-after-301-redirect
Logged
bobonwhidbey
Hero Member
Posts: 630
Re: Obtain an expanded URL from tinyurl.com
«
Reply #2 on:
September 07, 2016, 06:54:17 am »
I don't really understand this function. I tried this on a guess - with no luck.
InternetSetOption(nil, INTERNET_STATUS_REDIRECT, @Buffer, BufferLen);
How should this be formated?
Logged
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64
Leledumbo
Hero Member
Posts: 8835
Programming + Glam Metal + Tae Kwon Do = Me
Re: Obtain an expanded URL from tinyurl.com
«
Reply #3 on:
September 07, 2016, 07:58:55 am »
MUCH shorter and cross platform:
Code: Pascal
[Select]
[+]
[-]
{$mode objfpc}
uses
SysUtils
,
fphttpclient
;
begin
with
TFPHTTPClient
.
Create
(
nil
)
do
try
HTTPMethod
(
'HEAD'
,
'http://tinyurl.com/jrs3grj'
,
nil
,
[
301
]
)
;
// just use HEAD, we're not interested in the body, there will be none anyway
ResponseHeaders
.
NameValueSeparator
:
=
':'
;
// HTTP header uses colon as separator
WriteLn
(
Trim
(
ResponseHeaders
.
Values
[
'Location'
]
)
)
;
// there will be a space in front of the value, hence the Trim()
finally
Free
;
end
;
end
.
Logged
Follow this if you want me to answer:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F
http://pascalgeek.blogspot.com
https://bitbucket.org/leledumbo
https://github.com/leledumbo
Code first, think later - Natural programmer B)
bobonwhidbey
Hero Member
Posts: 630
Re: Obtain an expanded URL from tinyurl.com
«
Reply #4 on:
September 07, 2016, 03:31:29 pm »
This worked perfectly Leledumbo. Thank you very much.
«
Last Edit: September 07, 2016, 03:37:56 pm by bobonwhidbey
»
Logged
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
[solved] Obtain an expanded URL from tinyurl.com
TinyPortal
© 2005-2018