Rust
Rust
SimpleTexting - Send SMS Message
See more SimpleTexting Examples
Send a text message to an individual contact.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Implements the following CURL command:
// curl --request POST \
// --url 'https://app2.simpletexting.com/v1/send?token=YOUR_API_TOKEN&phone=SOME_STRING_VALUE&message=SOME_STRING_VALUE' \
// --header 'accept: application/json' \
// --header 'content-type: application/x-www-form-urlencoded'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
http.set_request_header("accept", "application/json");
http.set_request_header("content-type", "application/x-www-form-urlencoded");
let req = chilkat::HttpRequest::new();
req.add_param("token", "YOUR_API_TOKEN");
req.add_param("phone", "SOME_10_DIGIT_PHONE_NUMBER");
req.add_param("message", "Hello: This is a sample text message with some punctuation: &%$@,;.");
req.add_header("Accept", "application/json");
req.set_http_verb("POST");
req.set_content_type("application/x-www-form-urlencoded");
let resp = chilkat::HttpResponse::new();
if http.http_req("https://app2.simpletexting.com/v1/send", &req, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "code": 1,
// "message": "The request succeeded",
// "smsid": "5bec5b9d0a975a238808ffb2"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let code = j_resp.int_of("code");
let message = j_resp.string_of("message").unwrap_or_default();
let smsid = j_resp.string_of("smsid").unwrap_or_default();