Sample code for 30+ languages & platforms
Rust

Get a REST Response Header Value by Index

See more REST Examples

Demonstrates Rest.ResponseHdrValue, which returns the value of the response header at a zero-based index. The same index used with ResponseHdrName gives the corresponding field name.

Background. Response headers can be enumerated by index from 0 through NumResponseHeaders minus one, after ReadResponseHeader has been called.

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 the response header at a zero-based index.  Use the same index with
// ResponseHdrName to get the corresponding field name.
let num_headers = rest.num_response_headers();
for i in 0..num_headers {
    let Ok(value) = rest.response_hdr_value(i) else {
        println!("{}", rest.last_error_text());
        return;
    };

    println!("Header {} value: {}", i, value);
}