我如何在 Rust futures reqwest 中接受无效或自签名的 SSL 证书?
How can I accept invalid or self-signed SSL certificates in Rust futures reqwest?
我的代码如下所示:
let fetches = futures::stream::iter(
hosts.into_iter().map(|url| {
async move {
match reqwest::get(&url).await {
// Ok and Err statements here!
}
但是,这里的问题是它会为具有无效或自签名 SSL 证书的 URL 提供错误。因此,我尝试执行以下操作:
let fetches = futures::stream::iter(
hosts.into_iter().map(|url| {
async move {
match reqwest::Client::builder().danger_accept_invalid_certs(true).build().unwrap().get(&url).await {
// Ok and Err statements here!
}
当我尝试使用 Cargo 构建它时,它显示“错误[E0277]:`RequestBuilder` 不是未来”。
那么,如何让我的代码接受无效证书?
不同于顶级 get()
function, which returns a Response
, the Client::get()
method which you call in second code, returns a RequestBuilder
, which you must send()
实际交流。
添加缺少的 send()
允许代码编译 (playgropund):
fn main() {
let hosts: Vec<String> = vec![];
let fetches = futures::stream::iter(hosts.into_iter().map(|url| async move {
match reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap()
.get(&url)
.send()
.await
{
Ok(x) => x,
Err(x) => panic!(),
}
}));
}
我的代码如下所示:
let fetches = futures::stream::iter(
hosts.into_iter().map(|url| {
async move {
match reqwest::get(&url).await {
// Ok and Err statements here!
}
但是,这里的问题是它会为具有无效或自签名 SSL 证书的 URL 提供错误。因此,我尝试执行以下操作:
let fetches = futures::stream::iter(
hosts.into_iter().map(|url| {
async move {
match reqwest::Client::builder().danger_accept_invalid_certs(true).build().unwrap().get(&url).await {
// Ok and Err statements here!
}
当我尝试使用 Cargo 构建它时,它显示“错误[E0277]:`RequestBuilder` 不是未来”。
那么,如何让我的代码接受无效证书?
不同于顶级 get()
function, which returns a Response
, the Client::get()
method which you call in second code, returns a RequestBuilder
, which you must send()
实际交流。
添加缺少的 send()
允许代码编译 (playgropund):
fn main() {
let hosts: Vec<String> = vec![];
let fetches = futures::stream::iter(hosts.into_iter().map(|url| async move {
match reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap()
.get(&url)
.send()
.await
{
Ok(x) => x,
Err(x) => panic!(),
}
}));
}