Sample code for 30+ languages & platforms
PHP Extension

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 PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

$success = false;

$rest = new CkRest();
$bTls = true;
$bAutoReconnect = true;
$success = $rest->Connect('example.com',443,$bTls,$bAutoReconnect);
if ($success == false) {
    print $rest->lastErrorText() . "\n";
    exit;
}

$success = $rest->SendReqNoBody('GET','/api/items/123');
if ($success == false) {
    print $rest->lastErrorText() . "\n";
    exit;
}

$statusCode = $rest->ReadResponseHeader();
if ($statusCode < 0) {
    print $rest->lastErrorText() . "\n";
    exit;
}

//  Return the value of a response header field by name.  Header field names are case-insensitive.
$contentType = $rest->responseHdrByName('Content-Type');
if ($rest->get_LastMethodSuccess() == false) {
    print $rest->lastErrorText() . "\n";
    exit;
}

print 'Content-Type: ' . $contentType . "\n";

?>