Swift
Swift
Example: Http.ExtractMetaRefreshUrl method
Demonstrates theExtractMetaRefreshUrl method.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let http = CkoHttp()!
// 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>
let sb = CkoStringBuilder()!
var bCrlf: Bool = true
sb.appendLine(str: "<!DOCTYPE html>", crlf: bCrlf)
sb.appendLine(str: "<html lang=\"en\">", crlf: bCrlf)
sb.appendLine(str: "<head>", crlf: bCrlf)
sb.appendLine(str: " <meta charset=\"utf-8\" />", crlf: bCrlf)
sb.appendLine(str: " <meta http-equiv=\"refresh\" content=\"5; url=https://example.com\" />", crlf: bCrlf)
sb.appendLine(str: " <title>Meta Refresh Redirect</title>", crlf: bCrlf)
sb.appendLine(str: "</head>", crlf: bCrlf)
sb.appendLine(str: "<body>", crlf: bCrlf)
sb.appendLine(str: " <p>Redirecting to example.com in 5 seconds�</p>", crlf: bCrlf)
sb.appendLine(str: "</body>", crlf: bCrlf)
sb.appendLine(str: "</html>", crlf: bCrlf)
var url: String? = http.extractMetaRefreshUrl(html: sb.getAsString())
if http.lastMethodSuccess == false {
print("The HTML has no META refresh tag.")
}
else {
print("META refresh URL: \(url!)")
}
}