Rust
Rust
Explaining the Rest ClearResponseBodyStream Method
See more Azure Cloud Storage Examples
The ClearResponseBodyStream method would be needed if your applicaiton called SetResponseBodyStream to send the response to a stream for one request, but then wants to subsequently do something else. The application must call ClearResponseBodyStream to no longer send responses to the stream.Chilkat Rust Downloads
let mut success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = chilkat::Rest::new();
// Connect to the web server
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
success = rest.connect("www.chilkatsoft.com", port, b_tls, b_auto_reconnect).is_ok();
if !success {
println!("{}", rest.last_error_text());
return;
}
// Setup a file stream for the download
let file_stream = chilkat::Stream::new();
file_stream.set_sink_file("qa_output/starfish.jpg");
// Indicate that the call to FullRequestNoBody should send the response body
// to fileStream if the response status code is 200.
// If a non-success response status code is received, then nothing
// is streamed to the output file and the error response is returned by FullRequestNoBody.
let expected_status = 200;
let _ = rest.set_response_body_stream(expected_status, true, &file_stream);
let response_str = rest.full_request_no_body("GET", "/images/starfish.jpg").unwrap_or_default();
if !rest.last_method_success() {
// 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!("downloaded starfish.jpg");
// Clear the response body stream previously set in the call to SetResponseBodyStream.
rest.clear_response_body_stream();
// Download something else, but this time send the response body to bd.
let bd = chilkat::BinData::new();
success = rest.full_request_no_body_bd("GET", "/images/penguins.jpg", &bd).is_ok();
if !success {
// 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): {}", bd.get_string("utf-8").unwrap_or_default());
println!("---");
println!("LastRequestStartLine: {}", rest.last_request_start_line());
println!("LastRequestHeader: {}", rest.last_request_header());
return;
}
// Save the contents of bd to a file.
success = bd.write_file("qa_output/penguins.jpg").is_ok();
println!("Success: {}", success);