(C) Inspect HTTP Request Header
Demonstrates the LastHeader property.
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
const char *url;
const char *json;
HCkHttpResponse resp;
success = FALSE;
http = CkHttp_Create();
url = "https://chilkatsoft.com/echo_request_body.asp";
json = "{\"greeting\":\"Hello World\"}";
// Send a POST with the JSON in the HTTP request body.
resp = CkHttpResponse_Create();
success = CkHttp_HttpStr(http,"POST",url,json,"utf-8","application/json",resp);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
return;
}
// Examine the HTTP request header we just sent.
printf("%s\n",CkHttp_lastHeader(http));
// Output:
// POST /echo_request_body.asp HTTP/1.1
// Host: chilkatsoft.com
// Accept: */*
// Accept-Encoding: gzip
// Content-Type: application/json
// Content-Length: 26
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
}
|