Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
HTTP Download Binary or Text to Memory or Stream to FileHTTP download into memory, or stream directly to a file. Demonstrates downloading both binary and string HTTP responses to memory.
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.