Browse Source

reqwest using a client with post request

main
crunk 1 year ago
parent
commit
30b76f69ce
  1. 10
      src/main.rs

10
src/main.rs

@ -7,20 +7,20 @@ use clap::Parser;
struct Cli { struct Cli {
url: String, url: String,
text: String,
} }
// This is using the `tokio` runtime. You'll need the following dependency:
//
// `tokio = { version = "1", features = ["full"] }`
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), reqwest::Error> { async fn main() -> Result<(), reqwest::Error> {
// Some simple CLI args requirements... // Some simple CLI args requirements...
let args = Cli::parse(); let args = Cli::parse();
let url = args.url; let url = args.url;
let text = args.text;
eprintln!("Fetching {:?}...", url); let client = reqwest::Client::new();
let res = reqwest::get(url).await?; let res = client.post(url).body(text).send().await?;
eprintln!("Response: {:?} {}", res.version(), res.status()); eprintln!("Response: {:?} {}", res.version(), res.status());
eprintln!("Headers: {:#?}\n", res.headers()); eprintln!("Headers: {:#?}\n", res.headers());

Loading…
Cancel
Save