Sample code for 30+ languages & platforms
Java

Example: Http.ExtractMetaRefreshUrl method

Demonstrates the ExtractMetaRefreshUrl method.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        Http http = new Http();

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

        StringBuilder sb = new StringBuilder();
        boolean 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);

        String url = null;
        try {
            url = http.extractMetaRefreshUrl(sb.getAsString());
            System.out.println("META refresh URL: " + url);
        } catch (ChilkatException e) {
            System.out.println("The HTML has no META refresh tag.");
        }
    }
}