//这个函数的返回值的String 是响应体 字符串
async fn send_post() -> Result<String, reqwest::Error> {
let client = reqwest::Client::new();
//post 请求头
let mut header = HeaderMap::new();
header.insert("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/110.0.0.0 Safari/537.36".parse().expect("unsolve the userAgent header value."),
);
header.insert("referer", "https//www.aaa.com".parse().expect("unsolve the referer value."));
header.insert("sec-ch-ua", "sec-ch-ua".parse().expect("ms"));
// post 请求体
let mut data = HashMap::new();
//用户输入
//get_user_input().await;
data.insert("prompt", "aaa");
Ok(client.post("https://这里是连接地址")
.headers(header)
.json(&data)//把data 转json 格式 {"prompt","aaa"}
.send()
.await?// 这里是response 对象
.text()
.await?
)
}
rust 发送post 请求 响应json
最新推荐文章于 2024-04-27 18:15:09 发布