Unicode C
Unicode C
Get a REST Response Header by Name
See more REST Examples
Demonstrates Rest.ResponseHdrByName, which returns the value of a response header field by name. Header field names are case-insensitive.
Background. Response headers are available after ReadResponseHeader has read the status line and headers. Lookup by name is convenient when a specific header, such as Content-Type, is needed.
Chilkat Unicode C Downloads
#include <C_CkRestW.h>
void ChilkatSample(void)
{
BOOL success;
HCkRestW rest;
BOOL bTls;
BOOL bAutoReconnect;
int statusCode;
const wchar_t *contentType;
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 a response header field by name. Header field names are case-insensitive.
contentType = CkRestW_responseHdrByName(rest,L"Content-Type");
if (CkRestW_getLastMethodSuccess(rest) == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
wprintf(L"Content-Type: %s\n",contentType);
CkRestW_Dispose(rest);
}