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 <C_CkRestW.h>
void ChilkatSample(void)
{
BOOL success;
HCkRestW rest;
BOOL bTls;
BOOL bAutoReconnect;
int statusCode;
int numHeaders;
int i;
const wchar_t *value;
success = FALSE;
rest = CkRestW_Create();
bTls = TRUE;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"example.com",443,bTls,bAutoReconnect);
if (success == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
success = CkRestW_SendReqNoBody(rest,L"GET",L"/api/items/123");
if (success == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
statusCode = CkRestW_ReadResponseHeader(rest);
if (statusCode < 0) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
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.
numHeaders = CkRestW_getNumResponseHeaders(rest);
for (i = 0; i <= numHeaders - 1; i++) {
value = CkRestW_responseHdrValue(rest,i);
if (CkRestW_getLastMethodSuccess(rest) == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
wprintf(L"Header %d value: %s\n",i,value);
}
CkRestW_Dispose(rest);
}