alexcrichton / curl-rust

Rust bindings to libcurl
MIT License
1.02k stars 235 forks source link

get data from transfer function #289

Closed linkwik closed 5 years ago

linkwik commented 5 years ago

How to get status_code and primary_ip data from the transfer function? currently working code, want to increase data of getting status_code and primary_ip, but prompt transfer function error code:

let mut dst = Vec::new();
let mut c = Easy::new();
c.url(&domain);
c.certinfo(true).ok().expect("Show cert Error!");
c.show_header(true).ok().expect("Show Header Error!");
c.timeout(Duration::new(60, 0));
 {
    let mut t = c.transfer();
    t.write_function(|data| {
        dst.extend_from_slice(data);
        Ok(data.len())
     }).unwrap();
     match t.perform() {
        Ok(_) => {},
        Err(_) => {}
     }
}

Error Message: error[E0599]: no method named primary_ip found for type curl::easy::Transfer<'_, '_> in the current scope

alexcrichton commented 5 years ago

Thanks for the report! Typically after performing a transfer you'll return to the outer scope and read properties off the original Easy handle. Only some properties (mostly callbacks) are offered on Transfer