Created
December 25, 2019 12:29
-
-
Save geekswamp/1eaae906539c97185b46608390ec7fb1 to your computer and use it in GitHub Desktop.
Post with Reqwest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "sysinfo" | |
version = "0.1.0" | |
authors = ["Ahmad Rifa'i <[email protected]>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
# sys-info = "*" | |
whoami = "0.6.0" | |
serde_json = "1.0" | |
serde = { version = "1.0", features = ["derive"] } | |
reqwest = "0.9.24" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate whoami; | |
extern crate reqwest; | |
use serde::{Deserialize, Serialize}; | |
// use serde_json; | |
#[derive(Serialize, Deserialize, Debug)] | |
struct Sysinfo { | |
username: String, | |
computer_name: String, | |
platform: String, | |
os_version: String, | |
} | |
fn get_sysinfo() -> Result<(), reqwest::Error> { | |
let sysinfo = Sysinfo { | |
username: whoami::username(), | |
computer_name: whoami::hostname(), | |
platform: whoami::platform().to_string(), | |
os_version: whoami::os(), | |
}; | |
let client = reqwest::Client::new(); | |
let res = client.post("https://jsonplaceholder.typicode.com/posts") // ganti url server | |
.json(&sysinfo) | |
.send(); | |
println!("{:#?}", res); | |
Ok(()) | |
// let to_json = serde_json::to_string(&sysinfo); | |
// println!("{}", to_json.unwrap()); | |
} | |
fn main() { | |
match get_sysinfo() { | |
Err(e) => println!("{:?}", e), | |
_ => () | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment