Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

TicketBAI -- Send HTTP POST

See more TicketBAI Examples

Demonstrates how to send a TicketBAI POST and get the response.

Chilkat Rust Downloads

Rust

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

let http = chilkat::Http::new();

if http.set_ssl_client_cert_pfx("your.pfx", "pfx_password").is_err() {
    println!("{}", http.last_error_text());
    return;
}

// Get the XML we wish to send in the body of the request.
let sb_xml = chilkat::StringBuilder::new();
if sb_xml.load_file("qa_data/payload.xml", "utf-8").is_err() {
    println!("Failed to load XML that is to be the HTTP request body");
    return;
}

// Build the following JSON

// { 
//     "con": "LROE", 
//     "apa": "1.1", 
//     "inte": { 
//         "nif": "número de identificación fiscal", 
//         "nrs": "nombre o Razón social", 
//         "ap1": "primer apellido", 
//         "ap2": "segundo apellido" 
//     }, 
//     "drs": { 
//     "mode": "140", 
//     "ejer": "ejercicio" 
//     } 
// }

// Use this online tool to generate code from sample JSON: 
// Generate Code to Create JSON

let json = chilkat::JsonObject::new();
let _ = json.update_string("con", "LROE");
let _ = json.update_string("apa", "1.1");
let _ = json.update_string("inte.nif", "número de identificación fiscal");
let _ = json.update_string("inte.nrs", "nombre o Razón social");
let _ = json.update_string("inte.ap1", "primer apellido");
let _ = json.update_string("inte.ap2", "segundo apellido");
let _ = json.update_string("drs.mode", "140");
let _ = json.update_string("drs.ejer", "ejercicio");

// Add required headers...
http.set_request_header("eus-bizkaia-n3-version", "1.0");
http.set_request_header("eus-bizkaia-n3-content-type", "application/xml");
http.set_request_header("eus-bizkaia-n3-data", &json.emit().unwrap_or_default());

let url = "https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena".to_string();
let resp = chilkat::HttpResponse::new();
http.set_uncommon_options("SendGzipped");
if http.http_sb("POST", &url, &sb_xml, "utf-8", "application/octet-stream", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

http.clear_headers();

println!("response status code: {}", resp.status_code());

// Examine the response (it is already decompressed)
println!("response body:");
println!("{}", resp.body_str());