(Unicode C++) HTTP POST with Binary Data in Request Body
Do an HTTPS POST with a binary request body.
#include <CkHttpW.h>
#include <CkFileAccessW.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.
CkHttpW http;
bool success;
CkFileAccessW fac;
CkByteData reqBody;
success = fac.ReadEntireFile(L"qa_data/pdf/helloWorld.pdf",reqBody);
const wchar_t *responseStr = http.postBinary(L"https://example.com/something",reqBody,L"application/pdf",false,false);
if (http.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
int responseStatusCode = http.get_LastStatus();
wprintf(L"Status code: %d\n",responseStatusCode);
// For example, if the response is XML, JSON, HTML, etc.
wprintf(L"response body:\n");
wprintf(L"%s\n",responseStr);
}
|