Dart
Dart
Example: Http.ExtractMetaRefreshUrl method
Demonstrates theExtractMetaRefreshUrl method.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
final http = 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>
final sb = CkStringBuilder();
final bCrlf = true;
sb.appendLine('<!DOCTYPE html>', bCrlf);
sb.appendLine('<html lang="en">', bCrlf);
sb.appendLine('<head>', bCrlf);
sb.appendLine(' <meta charset="utf-8" />', bCrlf);
sb.appendLine(' <meta http-equiv="refresh" content="5; url=https://example.com" />', bCrlf);
sb.appendLine(' <title>Meta Refresh Redirect</title>', bCrlf);
sb.appendLine('</head>', bCrlf);
sb.appendLine('<body>', bCrlf);
sb.appendLine(' <p>Redirecting to example.com in 5 seconds�</p>', bCrlf);
sb.appendLine('</body>', bCrlf);
sb.appendLine('</html>', bCrlf);
try {
final url = http.extractMetaRefreshUrl(sb.getAsString());
print('META refresh URL: $url');
} on ChilkatException {
print('The HTML has no META refresh tag.');
}
}