当我使用 reqwest 的客户端生成器时,有什么方法可以向代理添加基本身份验证?
Is there a way I can add basic auth to the proxy when I'm using reqwest's client builder?
我正在尝试使用 Reqwest 的代理功能将 user:pass 基本身份验证与 URL 的其余部分一起传递到代理功能中。显然,这个板条箱的基本身份验证工作方式不能以这种方式传递给代理。
当我注释掉代理时,我得到了我的数据,但它没有通过我的代理:
let raw_proxy = format!("https://{}:{}@{}", username, password, forward_proxy);
let proxy = reqwest::Proxy::all(&raw_proxy).unwrap();
let mut buf = &mut Vec::new();
File::open("../cert.der").unwrap().read_to_end(&mut buf).unwrap();
let cert = reqwest::Certificate::from_der(&buf).unwrap();
let client = reqwest::Client::builder()
.add_root_certificate(cert)
//.proxy(proxy)
.build().unwrap();
let mut res = client.post("http://httpbin.org/post")
.header(ContentType::json())
.body(format!("{}", redacted_data))
.send().unwrap();
简短的回答是你不能不写更多的代码。如需更长的答案,请参阅我 2 年前打开的这张票。 https://github.com/hyperium/hyper/issues/531
基本上,经过身份验证的代理目前无法使用。 headers 未更新。
作者支持,只是优先级不高。我不再支持代理,所以它也不再是我的代理。
如果您使用的是最新的reqwest版本,这个问题已经解决了。您需要确定您使用的是 HTTP 还是 HTTPS。要仔细检查它是否连接到代理,您可以使用像 Burp 这样的工具。
我在这里写了关于如何设置和测试代理、自签名证书和 Burp for reqwest 的完整指南 https://www.yodiw.com/rust-reqwest-via-proxy-and-ssl-certificate-captured-by-burp/
我正在尝试使用 Reqwest 的代理功能将 user:pass 基本身份验证与 URL 的其余部分一起传递到代理功能中。显然,这个板条箱的基本身份验证工作方式不能以这种方式传递给代理。
当我注释掉代理时,我得到了我的数据,但它没有通过我的代理:
let raw_proxy = format!("https://{}:{}@{}", username, password, forward_proxy);
let proxy = reqwest::Proxy::all(&raw_proxy).unwrap();
let mut buf = &mut Vec::new();
File::open("../cert.der").unwrap().read_to_end(&mut buf).unwrap();
let cert = reqwest::Certificate::from_der(&buf).unwrap();
let client = reqwest::Client::builder()
.add_root_certificate(cert)
//.proxy(proxy)
.build().unwrap();
let mut res = client.post("http://httpbin.org/post")
.header(ContentType::json())
.body(format!("{}", redacted_data))
.send().unwrap();
简短的回答是你不能不写更多的代码。如需更长的答案,请参阅我 2 年前打开的这张票。 https://github.com/hyperium/hyper/issues/531
基本上,经过身份验证的代理目前无法使用。 headers 未更新。
作者支持,只是优先级不高。我不再支持代理,所以它也不再是我的代理。
如果您使用的是最新的reqwest版本,这个问题已经解决了。您需要确定您使用的是 HTTP 还是 HTTPS。要仔细检查它是否连接到代理,您可以使用像 Burp 这样的工具。
我在这里写了关于如何设置和测试代理、自签名证书和 Burp for reqwest 的完整指南 https://www.yodiw.com/rust-reqwest-via-proxy-and-ssl-certificate-captured-by-burp/