Interacting with QBittorrent web API using Rust's reqwest crates with tokio(asynchronously).
I created an HTTP request according to the documentation of the QBittorrent web API, The request works in Postman and Python but for some reason not in rust.
The following code was pasted from Postman "Code Snippet".
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::builder()
.build()?;
let form = reqwest::multipart::Form::new()
.text("urls", "magnet:?xt=urn:btih:...")
.text("save_path", "C:\\Users\\user\\Downloads");
let request = client.request(reqwest::Method::POST, "http://localhost:2048/api/v2/torrents/add")
.multipart(form);
let response = request.send().await?;
let body = response.text().await?;
println!("{}", body);
Ok(())
}
On the docs.rs of reqwest crate multipart and Form do exist. https://docs.rs/reqwest/latest/reqwest/multipart/struct.Form.html
Getting this error:
failed to resolve: could not find multipart
in reqwest
could not find multipart
in reqwest
. (Line 6)
BTW: tried to use blocking version aswell, I get the same error.
These are the relevant dependencies:
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
reqwest = "0.11.18"
async-trait = "0.1.72"
That is happening because the multipart
feature flag is not enabled by default
. I would suggest to also check out the rust docs on this.
Therefore you will need to change your dependency on reqwest
like so
reqwest = { version = "0.11.18", features = ["multipart"] }