Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

let rest = chilkat::Rest::new();
let b_tls = true;
let b_auto_reconnect = true;
if rest.connect("example.com", 443, b_tls, b_auto_reconnect).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

if rest.send_req_no_body("GET", "/api/items/123").is_err() {
    println!("{}", rest.last_error_text());
    return;
}

let status_code = rest.read_response_header();
if status_code < 0 {
    println!("{}", rest.last_error_text());
    return;
}

// Return the value of a response header field by name.  Header field names are case-insensitive.
let Ok(content_type) = rest.response_hdr_by_name("Content-Type") else {
    println!("{}", rest.last_error_text());
    return;
};

println!("Content-Type: {}", content_type);