(Unicode C) HTTP POST JSON
Demonstrates how to send a JSON POST and get the JSON response.
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
const wchar_t *jsonText;
HCkHttpResponseW resp;
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code
http = CkHttpW_Create();
jsonText = L"{\"user\":\"doctoravatar@penzance.com\",\"forecast\":7,\"t\":\"vlIj\",\"zip\":94089}";
// IMPORTANT: Make sure to change the URL, JSON text,
// and other data items to your own values. The URL used
// in this example will not actually work.
resp = CkHttpW_PostJson(http,L"https://json.penzance.org/request",jsonText);
if (CkHttpW_getLastMethodSuccess(http) != TRUE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
}
else {
// Display the JSON response.
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
}
CkHttpW_Dispose(http);
}
|