Unicode C++
Unicode C++
Get a REST Response Header Value by Index
See more REST Examples
Demonstrates Rest.ResponseHdrValue, which returns the value of the response header at a zero-based index. The same index used with ResponseHdrName gives the corresponding field name.
Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one, after ReadResponseHeader has been called.
Chilkat Unicode C++ Downloads
#include <CkRestW.h>
void ChilkatSample(void)
{
bool success = false;
CkRestW rest;
bool bTls = true;
bool bAutoReconnect = true;
success = rest.Connect(L"example.com",443,bTls,bAutoReconnect);
if (success == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
success = rest.SendReqNoBody(L"GET",L"/api/items/123");
if (success == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int statusCode = rest.ReadResponseHeader();
if (statusCode < 0) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// Return the value of the response header at a zero-based index. Use the same index with
// ResponseHdrName to get the corresponding field name.
int numHeaders = rest.get_NumResponseHeaders();
int i;
for (i = 0; i <= numHeaders - 1; i++) {
const wchar_t *value = rest.responseHdrValue(i);
if (rest.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
wprintf(L"Header %d value: %s\n",i,value);
}
}