12

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
njaard
  • 529
  • 4
  • 15
  • Can you show the full error message? – E_net4 Jan 12 '17 at 17:57
  • You may want to check out [this answer](https://stackoverflow.com/questions/41614923/how-to-reach-an-https-site-via-proxy) that uses the new `hyper-native-tls` crate. – squiguy Jan 12 '17 at 18:22
  • For hyper 0.11, the answer is in the documentation under 'Client Configuration': https://hyper.rs/guides/client/configuration/ . – steamer25 Nov 17 '17 at 19:38

1 Answers1

19

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.

hansaplast
  • 11,007
  • 2
  • 61
  • 75
  • Interesting, so `hyper` ensure that you have a TLS-capable client before allowing the `https` scheme. That's neat! – Matthieu M. Jan 13 '17 at 07:59
  • 1
    @MatthieuM. I believe that was a recent change as TLS related code got put into the other crate. This code is using hyper 0.10. – squiguy Jan 13 '17 at 17:16