Sample code for 30+ languages & platforms
Rust

QuickGetBd Example

The QuickGetBd method is called to send a GET request to download a binary target, such as PDF, zip, image file, etc. into a Chilkat BinData object.

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();
http.set_keep_response_body(true);

let bd = chilkat::BinData::new();

// Download the contents of a PDF file into the bd object.
if http.quick_get_bd("https://www.chilkatsoft.com/hello.pdf", &bd).is_err() {
    // This will happen if the response status code was 400 or greater,
    // or if the request could not be sent, or if no response was received.
    // 
    // In other words, success will only be true if bd contains the desired content at the URL (not an error response).
    let status_code = http.last_status();
    println!("Response status: {}", status_code);

    if status_code == 0 {
        // There was an error in communications.  
        println!("{}", http.last_error_text());
    } else {
        // We received a response status code indicating failure.
        // Examine the response body.
        println!("{}", http.last_response_body());
    }

    return;
}

// Load the downloaded PDF into a Chilkat PDF object.
let pdf = chilkat::Pdf::new();
if pdf.load_bd(&bd).is_err() {
    println!("{}", pdf.last_error_text());
    return;
}

// ...

println!("Success.");