Sample code for 30+ languages & platforms
Node.js

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 Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var rest = new chilkat.Rest();
    var bTls = true;
    var bAutoReconnect = true;
    success = rest.Connect("example.com",443,bTls,bAutoReconnect);
    if (success == false) {
        console.log(rest.LastErrorText);
        return;
    }

    success = rest.SendReqNoBody("GET","/api/items/123");
    if (success == false) {
        console.log(rest.LastErrorText);
        return;
    }

    var statusCode = rest.ReadResponseHeader();
    if (statusCode < 0) {
        console.log(rest.LastErrorText);
        return;
    }

    //  Return the value of a response header field by name.  Header field names are case-insensitive.
    var contentType = rest.ResponseHdrByName("Content-Type");
    if (rest.LastMethodSuccess == false) {
        console.log(rest.LastErrorText);
        return;
    }

    console.log("Content-Type: " + contentType);

}

chilkatExample();