Zig
Zig
Example: Http.ExtractMetaRefreshUrl method
Demonstrates theExtractMetaRefreshUrl method.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const http = try chilkat.Http.init();
defer http.deinit();
// 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>
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
const b_crlf = true;
sb.appendLine("<!DOCTYPE html>", b_crlf) catch {};
sb.appendLine("<html lang=\"en\">", b_crlf) catch {};
sb.appendLine("<head>", b_crlf) catch {};
sb.appendLine(" <meta charset=\"utf-8\" />", b_crlf) catch {};
sb.appendLine(" <meta http-equiv=\"refresh\" content=\"5; url=https://example.com\" />", b_crlf) catch {};
sb.appendLine(" <title>Meta Refresh Redirect</title>", b_crlf) catch {};
sb.appendLine("</head>", b_crlf) catch {};
sb.appendLine("<body>", b_crlf) catch {};
sb.appendLine(" <p>Redirecting to example.com in 5 seconds�</p>", b_crlf) catch {};
sb.appendLine("</body>", b_crlf) catch {};
sb.appendLine("</html>", b_crlf) catch {};
const url = http.extractMetaRefreshUrl(alloc, try sb.getAsString(alloc)) catch "";
if (!http.getLastMethodSuccess()) {
std.debug.print("The HTML has no META refresh tag.\n", .{});
} else {
std.debug.print("META refresh URL: {s}\n", .{url});
}
}