(C++) HTTP POST with Binary Data in Request Body
Do an HTTPS POST with a binary request body.
#include <CkHttp.h>
#include <CkFileAccess.h>
#include <CkByteData.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http;
bool success;
CkFileAccess fac;
CkByteData reqBody;
success = fac.ReadEntireFile("qa_data/pdf/helloWorld.pdf",reqBody);
const char *responseStr = http.postBinary("https://example.com/something",reqBody,"application/pdf",false,false);
if (http.get_LastMethodSuccess() == false) {
std::cout << http.lastErrorText() << "\r\n";
return;
}
int responseStatusCode = http.get_LastStatus();
std::cout << "Status code: " << responseStatusCode << "\r\n";
// For example, if the response is XML, JSON, HTML, etc.
std::cout << "response body:" << "\r\n";
std::cout << responseStr << "\r\n";
}
|