次は、プロキシ経由でHTTPSサイトに到達しようとする試みである:Hyperでプロキシ経由でHTTPSサイトにアクセスするにはどうすればよいですか?
extern crate hyper;
extern crate hyper_native_tls;
use hyper::net::HttpsConnector;
use hyper::client::{Client, ProxyConfig};
use hyper_native_tls::NativeTlsClient;
fn main() {
let ssl = NativeTlsClient::new().unwrap();
let connector = HttpsConnector::new(ssl);
let client = Client::with_proxy_config(
ProxyConfig::new(
"http", "localhost", 3128, connector, ssl
)
);
let response = client.get("https://httpbin.org").send().unwrap();
println!("{}", response.headers);
}
私はこのエラーを取得する:ここで
error[E0277]: the trait bound `hyper_native_tls::TlsStream<hyper::net::HttpStream>: std::fmt::Debug` is not satisfied
--> src/main.rs:13:9
|
13 | ProxyConfig::new(
| ^^^^^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `hyper_native_tls::TlsStream<hyper::net::HttpStream>`
|
= note: `hyper_native_tls::TlsStream<hyper::net::HttpStream>` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
= note: required because of the requirements on the impl of `std::fmt::Debug` for `hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>`
= note: required because of the requirements on the impl of `hyper::net::SslClient<hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>>` for `hyper_native_tls::NativeTlsClient`
= note: required by `<hyper::client::ProxyConfig<C, S>>::new`
error[E0277]: the trait bound `hyper_native_tls::TlsStream<hyper::net::HttpStream>: std::fmt::Debug` is not satisfied
--> src/main.rs:13:9
|
13 | ProxyConfig::new(
| _________^ starting here...
14 | | "http", "localhost", 3128, connector, ssl
15 | | )
| |_________^ ...ending here: the trait `std::fmt::Debug` is not implemented for `hyper_native_tls::TlsStream<hyper::net::HttpStream>`
|
= note: `hyper_native_tls::TlsStream<hyper::net::HttpStream>` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
= note: required because of the requirements on the impl of `std::fmt::Debug` for `hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>`
= note: required because of the requirements on the impl of `hyper::net::SslClient<hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>>` for `hyper_native_tls::NativeTlsClient`
= note: required by `hyper::client::ProxyConfig`
error[E0277]: the trait bound `hyper_native_tls::TlsStream<hyper::net::HttpStream>: std::fmt::Debug` is not satisfied
--> src/main.rs:12:18
|
12 | let client = Client::with_proxy_config(
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `hyper_native_tls::TlsStream<hyper::net::HttpStream>`
|
= note: `hyper_native_tls::TlsStream<hyper::net::HttpStream>` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
= note: required because of the requirements on the impl of `std::fmt::Debug` for `hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>`
= note: required because of the requirements on the impl of `hyper::net::SslClient<hyper::net::HttpsStream<hyper_native_tls::TlsStream<hyper::net::HttpStream>>>` for `hyper_native_tls::NativeTlsClient`
= note: required by `hyper::Client::with_proxy_config`
は、貨物の依存関係です:
[dependencies]
hyper = "0.10"
hyper-native-tls = "0.2"
物事は優れています次の依存関係を使用します。
[dependencies]
hyper = "0.10"
hyper-openssl = "0.2"
そして、このコード:
extern crate hyper;
extern crate hyper_openssl;
use hyper::net::HttpsConnector;
use hyper::client::{Client, ProxyConfig};
use hyper_openssl::OpensslClient as TlsClient;
fn main() {
let ssl = TlsClient::new().unwrap();
let connector = HttpsConnector::new(ssl.clone());
let client = Client::with_proxy_config(
ProxyConfig::new(
"http", "localhost", 3128, connector, ssl
)
);
let response = client.get("https://httpbin.org").send().unwrap();
println!("{:#?}", response);
}
出力:
Response {
status: Ok,
headers: Headers { Server: nginx, Date: Thu, 12 Jan 2017 15:05:13 GMT, Content-Type: text/html; charset=utf-8, Content-Length: 12150, Connection: keep-alive, Access-Control-Allow-Origin: *, Access-Control-Allow-Credentials: true, },
version: Http11,
url: "https://httpbin.org/",
status_raw: RawStatus(
200,
"OK"
),
message: Http11Message {
is_proxied: false,
method: None,
stream: Wrapper {
obj: Some(
Reading(
SizedReader(remaining=12150)
)
)
}
}
}
ありませんが失敗を構築するが、それは、プロキシを経由しません。
これらのエラーのすべては、 'Debug'を実装していない間に' response'をデバッグモードで表示しようとしているという事実によるものではありませんか? – ljedrz
何も印刷しなくても同じエラーが出る – Tshepang
['hyper_native_tls'](https://docs.rs/hyper-native-tls/0.2.0/hyper_native_tls/)の構造はimplするように見えません'Debug'のため、そのコードに見られる動作は正しいでしょう。 'fmt()'を実行していないことを確認し、あなたの調査結果に質問を更新してください。 –