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 <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 a response header field by name. Header field names are case-insensitive.
const wchar_t *contentType = rest.responseHdrByName(L"Content-Type");
if (rest.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
wprintf(L"Content-Type: %s\n",contentType);
}