44 lines
831 B
Rust
44 lines
831 B
Rust
|
use std::error::Error;
|
||
|
|
||
|
use hyper::{
|
||
|
StatusCode,
|
||
|
Uri,
|
||
|
};
|
||
|
use reqwest::Client;
|
||
|
use tokio::fs::File;
|
||
|
|
||
|
#[tokio::main]
|
||
|
async fn main () -> Result <(), Box <dyn Error>> {
|
||
|
let client = Client::new ();
|
||
|
|
||
|
let path = "/home/user/pictures/bzqcChY.jpg";
|
||
|
|
||
|
loop {
|
||
|
let _uri = Uri::builder ()
|
||
|
.scheme ("http")
|
||
|
.authority ("127.0.0.1:4000")
|
||
|
.path_and_query ("/listen/alien_wildlands")
|
||
|
.build ().unwrap ();
|
||
|
|
||
|
let req = client.get ("http://127.0.0.1:4000/http_listen/alien_wildlands");
|
||
|
let response = match req.send ().await {
|
||
|
Err (e) => {
|
||
|
println! ("Err: {:?}", e);
|
||
|
continue;
|
||
|
},
|
||
|
Ok (r) => r,
|
||
|
};
|
||
|
|
||
|
if response.status () != StatusCode::OK {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
let body = response.bytes ().await?;
|
||
|
let body = std::str::from_utf8 (&body)?;
|
||
|
|
||
|
println! ("Client requested {}", body);
|
||
|
}
|
||
|
|
||
|
Ok (())
|
||
|
}
|