Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyper says "Invalid scheme for Http" for HTTPS URLs

I have

hyper = "0.10"

And the following code:

let client = Client::new();
let mut res = client.get("https://google.com").send().unwrap();

Rust gives me the error message, as if it doesn't have SSL support:

Invalid scheme for Http

This is on Rust 1.14.0 on Debian jessie.

How do I get Hyper to connect with SSL to an HTTPS URL?

like image 362
njaard Avatar asked Jan 12 '17 17:01

njaard


1 Answers

Try this:

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();
}

Mostly taken from this answer. What was missing was the Client::with_connector piece.

like image 176
hansaplast Avatar answered Sep 21 '22 10:09

hansaplast