Visual C++ Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
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...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

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.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
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);
	}

    }

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

Mail Component · .NET Mail Component · XML Parser