Sample code for 30+ languages & platforms
Tcl

Example: Http.ExtractMetaRefreshUrl method

Demonstrates the ExtractMetaRefreshUrl method.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set http [new_CkHttp]

# Sample HTML with a META refresh.

# <!DOCTYPE html>
# <html lang="en">
# <head>
#   <meta charset="utf-8" />
#   <meta http-equiv="refresh" content="5; url=https://example.com" />
#   <title>Meta Refresh Redirect</title>
# </head>
# <body>
#   <p>Redirecting to example.com in 5 seconds�</p>
# </body>
# </html>

set sb [new_CkStringBuilder]

set bCrlf 1
CkStringBuilder_AppendLine $sb "<!DOCTYPE html>" $bCrlf
CkStringBuilder_AppendLine $sb "<html lang=\"en\">" $bCrlf
CkStringBuilder_AppendLine $sb "<head>" $bCrlf
CkStringBuilder_AppendLine $sb "  <meta charset=\"utf-8\" />" $bCrlf
CkStringBuilder_AppendLine $sb "  <meta http-equiv=\"refresh\" content=\"5; url=https://example.com\" />" $bCrlf
CkStringBuilder_AppendLine $sb "  <title>Meta Refresh Redirect</title>" $bCrlf
CkStringBuilder_AppendLine $sb "</head>" $bCrlf
CkStringBuilder_AppendLine $sb "<body>" $bCrlf
CkStringBuilder_AppendLine $sb "  <p>Redirecting to example.com in 5 seconds�</p>" $bCrlf
CkStringBuilder_AppendLine $sb "</body>" $bCrlf
CkStringBuilder_AppendLine $sb "</html>" $bCrlf

set url [CkHttp_extractMetaRefreshUrl $http [CkStringBuilder_getAsString $sb]]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts "The HTML has no META refresh tag."
} else {
    puts "META refresh URL: $url"
}


delete_CkHttp $http
delete_CkStringBuilder $sb