我有
hyper = "0.10"
而下面的代码:
let client = Client::new();
let mut res = client.get("https://google.com").send().unwrap();
在Rust中,我收到了一个错误信息,好像它没有SSL支持:
无效的Http协议
这是在Debian jessie上的Rust 1.14.0版本。
如何让Hyper通过SSL连接到HTTPS URL?
试试这个:
extern crate hyper;
extern crate hyper_native_tls;
use hyper::Client;
use hyper::net::HttpsConnector;
use hyper_native_tls::NativeTlsClient;
fn main() {
let ssl = NativeTlsClient::new().unwrap();
let connector = HttpsConnector::new(ssl);
let client = Client::with_connector(connector);
let mut res = client.get("https://google.com").send().unwrap();
}
主要参考这个答案。缺失的是 Client::with_connector
部分。
hyper
在允许使用 https
方案之前确保你拥有能够处理 TLS 的客户端。这很棒! - Matthieu M.
hyper-native-tls
crate。链接 - squiguy