2
0

form.rs 843 B

1234567891011121314151617181920212223
  1. // Short example of a POST request with form data.
  2. //
  3. // This is using the `tokio` runtime. You'll need the following dependency:
  4. //
  5. // `tokio = { version = "1", features = ["full"] }`
  6. #[cfg(not(target_arch = "wasm32"))]
  7. #[tokio::main]
  8. async fn main() {
  9. let response = reqwest::Client::new()
  10. .post("http://www.baidu.com")
  11. .form(&[("one", "1")])
  12. .send()
  13. .await
  14. .expect("send");
  15. println!("Response status {}", response.status());
  16. }
  17. // The [cfg(not(target_arch = "wasm32"))] above prevent building the tokio::main function
  18. // for wasm32 target, because tokio isn't compatible with wasm32.
  19. // If you aren't building for wasm32, you don't need that line.
  20. // The two lines below avoid the "'main' function not found" error when building for wasm32 target.
  21. #[cfg(target_arch = "wasm32")]
  22. fn main() {}