Lua
Lua
Example: Http.ExtractMetaRefreshUrl method
Demonstrates theExtractMetaRefreshUrl method.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local success = false
local http = chilkat.Http.new()
-- 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>
local sb = chilkat.StringBuilder.new()
local bCrlf = true
sb:append_line("<!DOCTYPE html>", bCrlf)
sb:append_line("<html lang=\"en\">", bCrlf)
sb:append_line("<head>", bCrlf)
sb:append_line(" <meta charset=\"utf-8\" />", bCrlf)
sb:append_line(" <meta http-equiv=\"refresh\" content=\"5; url=https://example.com\" />", bCrlf)
sb:append_line(" <title>Meta Refresh Redirect</title>", bCrlf)
sb:append_line("</head>", bCrlf)
sb:append_line("<body>", bCrlf)
sb:append_line(" <p>Redirecting to example.com in 5 seconds�</p>", bCrlf)
sb:append_line("</body>", bCrlf)
sb:append_line("</html>", bCrlf)
local url = http:extract_meta_refresh_url(sb:get_as_string())
if not http.last_method_success then
print("The HTML has no META refresh tag.")
else
print("META refresh URL: " .. url)
end