Sample code for 30+ languages & platforms
Rust

Example: Http.ExtractMetaRefreshUrl method

Demonstrates the ExtractMetaRefreshUrl method.

Chilkat Rust Downloads

Rust

let 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>

let sb = chilkat::StringBuilder::new();
let b_crlf = true;
let _ = sb.append_line("<!DOCTYPE html>", b_crlf);
let _ = sb.append_line("<html lang=\"en\">", b_crlf);
let _ = sb.append_line("<head>", b_crlf);
let _ = sb.append_line("  <meta charset=\"utf-8\" />", b_crlf);
let _ = sb.append_line("  <meta http-equiv=\"refresh\" content=\"5; url=https://example.com\" />", b_crlf);
let _ = sb.append_line("  <title>Meta Refresh Redirect</title>", b_crlf);
let _ = sb.append_line("</head>", b_crlf);
let _ = sb.append_line("<body>", b_crlf);
let _ = sb.append_line("  <p>Redirecting to example.com in 5 seconds�</p>", b_crlf);
let _ = sb.append_line("</body>", b_crlf);
let _ = sb.append_line("</html>", b_crlf);

let url = http.extract_meta_refresh_url(&sb.get_as_string().unwrap_or_default()).unwrap_or_default();
if !http.last_method_success() {
    println!("The HTML has no META refresh tag.");
} else {
    println!("META refresh URL: {}", url);
}