Expand description
Multipart request support for the http-client
crate.
This module provides functionality to create and send multipart requests using the http-client
crate.
It supports file uploads, form fields, and custom headers for each part.
Example:
// Create a new multipart form.
let mut multipart = Multipart::new();
// Add a text field.
multipart.add_text("name", "John Doe");
// Add a file.
multipart.add_file("avatar", "examples/avatar.jpg", None).await?;
// Create a request.
let url = "https://httpbin.org/post".parse::<Url>()?;
let mut req = Request::new(Method::Post, url);
// Set the multipart body.
multipart.set_request(&mut req);
// Create a client.
let client = Client::new();
// Send the request.
let mut response = client.send(req).await?;
// Read the response body.
let body = response.body_string().await?;
// Print the response body.
println!("{}", body);
Structs§
- Multipart
- A struct representing a multipart form.