sender: receiver: basic reqwest implementation

This commit is contained in:
Patryk Hegenberg 2024-04-15 14:02:41 +02:00
parent 6a862648e7
commit f703d9517f
4 changed files with 56 additions and 20 deletions

View file

@ -1,4 +1,6 @@
use crate::http_client;
// use crate::http_client;
use reqwest::{Client, StatusCode};
use serde_json::Value;
use std::collections::HashMap;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
@ -8,14 +10,26 @@ pub async fn send_info(file: &str) -> Result<()> {
map.insert("keyword", "test");
map.insert("files", file);
let json_data = serde_json::to_string(&map)?;
// let json_data = serde_json::to_string(&map)?;
http_client::send_request(
"http://192.168.178.43:1323/upload".trim(),
"POST",
Some(json_data),
)
.await?;
let client = Client::new();
let res = client
.post("http://192.168.178.43:1323/upload")
.json(&map)
.send()
.await?;
if res.status() == StatusCode::CREATED {
let json: Value = res.json().await?;
println!("Json Response: {:#?}", json);
} else {
println!("Error reading response");
}
// http_client::send_request(
// "http://192.168.178.43:1323/upload".trim(),
// "POST",
// Some(json_data),
// )
// .await?;
Ok(())
}