parent
1e35d625d3
commit
00b4e70c95
|
@ -6,20 +6,15 @@ use hyper::{Body, Client, Method, Request};
|
||||||
pub async fn net_request(url: String, body: Vec<u8>) -> Vec<u8> {
|
pub async fn net_request(url: String, body: Vec<u8>) -> Vec<u8> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
|
|
||||||
let uri = url.parse().expect("Failed to parse URL");
|
let uri: hyper::Uri = url.parse().expect("Failed to parse URL");
|
||||||
|
|
||||||
let resp = if body.len() > 0 {
|
// always POST even if body is empty
|
||||||
// make a POST with a body
|
let req = Request::builder()
|
||||||
let req = Request::builder()
|
.method(Method::POST)
|
||||||
.method(Method::POST)
|
.uri(uri)
|
||||||
.uri(uri)
|
.body(Body::from(body))
|
||||||
.body(Body::from(body))
|
.expect("Failed to create POST request");
|
||||||
.expect("Failed to create POST request");
|
let resp = client.request(req).await.expect("Failed to POST");
|
||||||
client.request(req).await.expect("Failed to POST")
|
|
||||||
} else {
|
|
||||||
// make a GET request
|
|
||||||
client.get(uri).await.expect("Failed to GET")
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("Response: {}", resp.status());
|
println!("Response: {}", resp.status());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue