我试着用reqwest机箱发送http GET请求。以下代码起作用:
extern crate reqwest;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::blocking::get("https://en.wikipedia.org/wiki/Rust_(programming_language)")?
.text()?;
println!("{:#?}", resp);
Ok(())
}但是当我将URL更改为https://www.mongolbank.mn/时
响应体html显示以下错误,而不是我想要的...Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine...内容
发布于 2022-08-01 09:49:19
使用tokio运行时和用户代理绕过错误。用户代理您可以使用浏览器的调试工具包从浏览器中抓取它
use reqwest::{self, header};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>>{
let mut headers = header::HeaderMap::new();
headers.insert(header::USER_AGENT,
header::HeaderValue::from_static("Mozilla/5.0...."));
let client = reqwest::Client::builder()
.default_headers(headers)
.build()?;
let res = client.get("https://www.mongolbank.mn").send().await?;
println!("{:#?}", res);
Ok(())
}https://stackoverflow.com/questions/73190746
复制相似问题