连续重定向
let https = HttpsConnector::new();
let client = Client::builder(TokioExecutor::new()).build::<>(https);
let mut builder = hyper::Request::builder()
.method(method)
.uri(url);
for (key, value) in headers.iter() {
builder = builder.header(key, value);
}
let req = builder.body(Empty::<hyper::body::Bytes>::new())
.unwrap();
println!("req: {:?}", req);
let resp = client.request(req).await.unwrap();
println!("resp: {:?}", resp);
if let Some(localtion) = resp.headers().get(header::LOCATION) {
println!("location: {:?}", localtion);
if let Ok(location_str) = localtion.to_str() {
println!("Redirecting1 to: {}", location_str);
}
}
let https = HttpsConnector::new();
let client = Client::builder(TokioExecutor::new()).build::<_, Empty<hyper::body::Bytes>>(https);
let req = hyper::Request::builder()
.method(method)
.uri(url)
.body(Empty::<hyper::body::Bytes>::new())
.unwrap();
println!("req: {:?}", req);
let resp = client.request(req).await.unwrap();
println!("resp: {:?}", resp);
if let Some(localtion) = resp.headers().get(header::LOCATION) {
println!("location: {:?}", localtion);
if let Ok(location_str) = localtion.to_str() {
println!("Redirecting1 to: {}", location_str);
}
}
下面这一行有问题
for (key, value) in headers.iter() {
builder = builder.header(key, value);
}