Visual C++ Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Visual C++ Examples

CkString
Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

 

HTTP Download Binary or Text to Memory or Stream to File

HTTP download into memory, or stream directly to a file. Demonstrates downloading both binary and string HTTP responses to memory.

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

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

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

void ChilkatSample(void)
    {
    //  
// HTTP GET C++ Example:

    CkHttp http;

    // Unlock once at the beginning of your program.
    bool success = http.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        printf("%s\n",http.lastErrorText());
        return;
    }

    // A binary file can be downloaded directly into memory using QuickGet.
    // QuickGet sends an HTTP GET request to the URL and retrieves the HTTP binary response.
    // The data is saved in a CkByteData object.
    CkByteData binaryData;
    success = http.QuickGet("http://www.chilkatsoft.com/images/dude.gif",binaryData);

    if (success)
	{
	// You may access the data in-memory like this:
	const unsigned char *imageData = binaryData.getData();
	unsigned long numBytes = binaryData.getSize();

	// You may save the binary data to a file like this:
	binaryData.saveFile("dude.gif");
	}
    else
	{
	http.SaveLastError("httpError.xml");
	}


    // Alternatively, if a large file is to be downloaded such that it is too large
    // to hold in memory, you may call CkHttp::Download to do a streaming download directly
    // to a file:
    success = http.Download("http://www.chilkatsoft.com/images/dude.gif","dude2.gif");
    if (!success)
	{
	http.SaveLastError("httpError2.xml");
	}

    // If the HTTP response is text, such as for an XML file, you may call
    // QuickGetStr to download directly into a CkString object:
    CkString strXml;
    success = http.QuickGetStr("http://www.chilkatsoft.com/testData/hamlet.xml",strXml);
    if (!success)
	{
	http.SaveLastError("httpError3.xml");
	}
    else
	{
	// You may access the null-terminated string as Unicode, utf-8, or ANSI:
	const wchar_t *uniStr = strXml.getUnicode();	
	const char *utf8Str = strXml.getEnc("utf-8");
	const char *ansiStr = strXml.getEnc("ansi");
	
	printf("%s\n",ansiStr);
	}

    }

Need a specific example? Send a request to support@chilkatsoft.com

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

Mail Component · .NET Mail Component · XML Parser