These are chat archives for rust-lang/rust

14th
Jul 2016
Reto Trinkler
@retotrinkler
Jul 14 2016 15:25
hi
am very new to rust and wanted to ask how i can read the return of this rust-curl call and print it to the console: https://github.com/blockchain-hacklab/rust-interact/blob/master/interact/src/main.rs ?
thanks in advance
something along the lines of: println!("{}", easy.response_code().unwrap());
Reto Trinkler
@retotrinkler
Jul 14 2016 15:45
    let mut data = "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":1}".as_bytes();
    let mut easy = Easy::new();
    easy.url("http://localhost:8545").unwrap();
    easy.post(true).unwrap();
    easy.post_field_size(data.len() as u64).unwrap();

    {
        let mut transfer = easy.transfer();
        transfer.read_function(|buf| {
            Ok(data.read(buf).unwrap_or(0))
        }).unwrap();
        transfer.perform().unwrap();
    }

    println!("{}", easy.response_code().unwrap());
this worked
however only prints: 200
no response body..
anyone know how to get the response body?
Reto Trinkler
@retotrinkler
Jul 14 2016 16:11
ok don't mean to spam i think i get some response now with this:
    let mut data = "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":1}".as_bytes();
    let mut resp = Vec::new();
    let mut easy = Easy::new();
    easy.url("http://localhost:8545").unwrap();
    easy.post(true).unwrap();
    easy.post_field_size(data.len() as u64).unwrap();

    {
        let mut transfer = easy.transfer();
        transfer.read_function(|buf| {
            resp.extend_from_slice(buf);
            Ok(data.read(buf).unwrap_or(0))
        }).unwrap();
        transfer.perform().unwrap();
    }

    println!("{:?}", easy.response_code().unwrap());
    println!("{:?}", resp);
get as response:
200
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ..., 0]