Reqwest - REST api - problem

Hi,

I have this simple REST code . I use reqwest crate. The code is getting executed
but I dont see any traffic ot tcp connection to the port 8008. I use simple netcat utility
nc -l -p 8008 to check the tcp connection.

I could able to see the connection when I use curl or even telnet localhost 8008 .
This means my program do not make tcp connection as required.

Could any one help on this ?.

Thanks,
S.Gopinath

use reqwest;

pub fn main()
{

    let send_bytes : Vec<u8> = vec![0;100];
    let this_client = reqwest::Client::new()
             .post("http://localhost:8008/batches")
             .header("Content-Type", "application/octet-stream")
             .body(send_bytes);

    println!("After send");
}

sorry.. I missed send() function.. sorry for troiubling the group

Even after send(); , it is not working.

Here is my code again

use reqwest;

pub fn main()
{

    let send_bytes : Vec<u8> = vec![0;100];
    let this_client = reqwest::Client::new()
             .post("http://localhost:8008/batches")
             .header("Content-Type", "application/octet-stream")
             .body(send_bytes)
             .send();

    println!("After send");
}

I dont see any tcp connect the program makes to port 8008 to localhost.

I believe reqwest is async and you will have to .await. (Futures need to be awaited or polled to do anything). The readme at GitHub - seanmonstar/reqwest: An easy and powerful Rust HTTP Client has a good example.

Which version of reqwest are you using? With the newest version you have to use the reqwest::blocking::Client instead.

Yes. Alice .. just tried and working.

Programming in Rust requires lots of reading and the subtle conepts to be understood.
Thats a a big gradient!!!

use reqwest;

fn main()
{

    let send_bytes : Vec<u8> = vec![0;100];
    let this_client = reqwest::blocking::Client::new()
             .post("http://localhost:8008/batches")
             .header("Content-Type", "application/octet-stream")
             .body(send_bytes)
             .send().expect("Error");

    println!("After send");
}

You should post the error message you get next time you ask a question. Otherwise I can only try to guess what is wrong.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.