add ClientBuilder.default_headers() for wasm32 target (#1084)
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
// Short example of a POST request with form data.
|
||||
//
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
reqwest::Client::new()
|
||||
let response = reqwest::Client::new()
|
||||
.post("http://www.baidu.com")
|
||||
.form(&[("one", "1")])
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
.expect("send");
|
||||
println!("Response status {}", response.status());
|
||||
}
|
||||
|
||||
// The [cfg(not(target_arch = "wasm32"))] above prevent building the tokio::main function
|
||||
// for wasm32 target, because tokio isn't compatible with wasm32.
|
||||
// If you aren't building for wasm32, you don't need that line.
|
||||
// The two lines below avoid the "'main' function not found" error when building for wasm32 target.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn main() {}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// This is using the `tokio` runtime. You'll need the following dependency:
|
||||
//
|
||||
// `tokio = { version = "0.2", features = ["macros"] }`
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), reqwest::Error> {
|
||||
let res = reqwest::get("https://hyper.rs").await?;
|
||||
@@ -15,3 +16,10 @@ async fn main() -> Result<(), reqwest::Error> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// The [cfg(not(target_arch = "wasm32"))] above prevent building the tokio::main function
|
||||
// for wasm32 target, because tokio isn't compatible with wasm32.
|
||||
// If you aren't building for wasm32, you don't need that line.
|
||||
// The two lines below avoid the "'main' function not found" error when building for wasm32 target.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn main() {}
|
||||
|
||||
Reference in New Issue
Block a user