Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

HTTP in a Background Thread (Asynchronous HTTP)

This example shows the technique one would follow to run any Chilkat HTTP method in a background task. (Only HTTP methods that communicate with an HTTP server are background-enabled. Methods that perform no HTTP communications return immediately and never need to be backgrounded.)

Download Chilkat C/C++ Libraries for VC++ 10.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 10.0 / x64

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 9.0 / x64

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

#include <CkHttp.h>

void ChilkatSample(void)
    {
    CkHttp http;

    bool success;

    //  Any string unlocks the component for the 1st 30-days.
    success = http.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        printf("%s\n",http.lastErrorText());
        return;
    }

    //  To run an HTTP method asynchronously in a background thread, set
    //  the UseBgThread property equal to true
    http.put_UseBgThread(true);

    //  For those programming languages that support event callbacks:
    //  events are not fired when a task is running in the background thread.
    //  Instead, Chilkat has added the "event log" mechanism.  While the
    //  background task is running, events that normally would've been fired
    //  are accumulated in the event log.  Your application may periodically check
    //  the event log to keep track of the progress of the background task.
    //  To enable event logging, set the KeepEventLog property = true
    http.put_KeepEventLog(true);

    //  Start an asynchronous HTTP download in a background thread.
    //  The method will return cktrue if the task was successfully started.
    //  Note: When the UseBgThread property = true, all methods involving
    //  HTTP communications will be asynchronous.  These methods include:
    //  SynchronousRequest, QuickGetStr, QuickGet, PostUrlEncoded, XmlRpc,
    //  XmlRpcPut, QuickPutStr, QuickGetObj, QuickDeleteStr, PutText,
    //  PutBinary, PostBinary, PostMime, GetHead, DownloadAppend, etc.
    success = http.Download("http://www.chilkatsoft.com/download/ChilkatJava.zip","ChilkatJava.zip");
    if (success != true) {
        printf("%s\n",http.lastErrorText());
        return;
    }
    else {
        printf("Initiated asynchronous HTTP download...\n");
    }

    //  Write a loop to wait for the background task to complete.
    //  Your application would typically do something different than this --
    //  after all... there's no point in doing the task asynchronously if your application
    //  is simply going to wait for it to complete -- that's the same as doing it synchronously,
    //  and that could've been achieved by a single call to the http.Download method
    //  with the UseBgThread = false.
    //  However... we do this here for the purpose of demonstration...
    while ((http.get_BgTaskRunning() == true)) {
        //  Show the events in the event log that have accumulated so far...
        long n;
        n = http.get_EventLogCount();
        if (n > 0) {
            long i;
            for (i = 0; i <= n - 1; i++) {
                printf("%s: %s\n",http.eventLogName(i)
                    ,http.eventLogValue(i));
            }

            http.ClearEventLog();
        }

        //  In some programming languages, you might wish to handle user-interface events
        //  For example, in C#  you might call Application.DoEvents()

        //  Sleep .1 seconds -- to keep the CPU from being 100% busy...
        http.SleepMs(100);
    }

    //  Once the background task has completed, check it for success/failure:
    if (http.get_BgTaskSuccess()) {
        printf("Background task completed successfully.\n");
    }


    }

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Mail Component · XML Parser