Sample code for 30+ languages & platforms
Unicode C

Example: Http.ExtractMetaRefreshUrl method

Demonstrates the ExtractMetaRefreshUrl method.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkStringBuilderW sb;
    BOOL bCrlf;
    const wchar_t *url;

    success = FALSE;

    http = CkHttpW_Create();

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

    sb = CkStringBuilderW_Create();
    bCrlf = TRUE;
    CkStringBuilderW_AppendLine(sb,L"<!DOCTYPE html>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"<html lang=\"en\">",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"<head>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"  <meta charset=\"utf-8\" />",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"  <meta http-equiv=\"refresh\" content=\"5; url=https://example.com\" />",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"  <title>Meta Refresh Redirect</title>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"</head>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"<body>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"  <p>Redirecting to example.com in 5 seconds�</p>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"</body>",bCrlf);
    CkStringBuilderW_AppendLine(sb,L"</html>",bCrlf);

    url = CkHttpW_extractMetaRefreshUrl(http,CkStringBuilderW_getAsString(sb));
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"The HTML has no META refresh tag.\n");
    }
    else {
        wprintf(L"META refresh URL: %s\n",url);
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sb);

    }