Rust
Rust
POST application/x-www-form-urlencoded using REST API
See more REST Examples
Demonstrates how to send a POST with query params (x-www-form-urlencoded) using the Chilkat REST object.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = chilkat::Rest::new();
// This example will send to https://www.chilkatsoft.com/echoPost.asp
// Make the initial connection (without sending a request yet).
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
if rest.connect("www.chilkatsoft.com", port, b_tls, b_auto_reconnect).is_err() {
println!("{}", rest.last_error_text());
return;
}
// Provide query params.
let _ = rest.add_query_param("firstName", "John");
let _ = rest.add_query_param("lastName", "Doe");
let _ = rest.add_query_param("company", "Bisco Bits Ltd.");
let Ok(response_str) = rest.full_request_form_url_encoded("POST", "/echoPost.asp") else {
println!("{}", rest.last_error_text());
return;
};
// When successful, the response status code will equal 200.
if rest.response_status_code() != 200 {
// Examine the request/response to see what happened.
println!("response status code = {}", rest.response_status_code());
println!("response status text = {}", rest.response_status_text());
println!("response header: {}", rest.response_header());
println!("response body (if any): {}", response_str);
println!("---");
println!("LastRequestStartLine: {}", rest.last_request_start_line());
println!("LastRequestHeader: {}", rest.last_request_header());
return;
}
println!("{}", response_str);
println!("Success.");