Rust
Rust
HTTPS Upload File to Web Server
See more HTTP Examples
Uploads a file to a web server using HTTPS.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The ContentType, HttpVerb, and Path properties should
// always be explicitly set.
let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_path("/receiveMyUpload.aspx");
req.set_content_type("multipart/form-data");
let _ = req.add_string_for_upload("fileA", "fileA.txt", "This is the contents of file A", "utf-8");
if req.add_file_for_upload("starfish.jpg", "qa_data/jpg/starfish.jpg").is_err() {
println!("{}", req.last_error_text());
return;
}
let http = chilkat::Http::new();
// ----------------------------------------------------------------------------
// IMPORTANT:
// HTTP uploads require a counterpart implementation on the server, written in any desired language
// such as C#, Classic ASP, PHP, etc., which consumes the upload being sent.
// See: ASP.NET Receive Upload
// ----------------------------------------------------------------------------
// Do the upload.
let use_ssl_tls = true;
let resp = chilkat::HttpResponse::new();
if http.http_s_req("www.example.com", 443, use_ssl_tls, &req, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("response status code = {}", resp.status_code());
println!("response body:");
println!("{}", resp.body_str());