主要是白天折磨了半天,无论如何post出去都不能成功,搞得我专门修改了一堆server的代码,以拦截任何访问服务器的数据,结果还是返回502,结果晚上回来一遍过,也真是奇怪的不行。先把一遍过的代码放出来,防止哪天又卡在这儿过不去。
//main.rs
use reqwest::Error;
//main.rs
async fn post_request() -> Result<(), Error> {
let url = "http://localhost:30241/dfc/get_block_stock";
let json_data = r#"{"block_source": "gnn"}"#;
let client = reqwest::Client::new();
let response = client
.post(url)
.header("Content-Type", "application/json")
.body(json_data.to_owned())
.send()
.await?;
println!("Status Code: {}", response.status());
let response_body = response.text().await?;
println!("Response body: \n{}", response_body);
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Error> {
post_request().await?;
Ok(())
}
Ca