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> {
|
||||
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 {
|
||||
// make a POST with a body
|
||||
let req = Request::builder()
|
||||
.method(Method::POST)
|
||||
.uri(uri)
|
||||
.body(Body::from(body))
|
||||
.expect("Failed to create POST request");
|
||||
client.request(req).await.expect("Failed to POST")
|
||||
} else {
|
||||
// make a GET request
|
||||
client.get(uri).await.expect("Failed to GET")
|
||||
};
|
||||
// always POST even if body is empty
|
||||
let req = Request::builder()
|
||||
.method(Method::POST)
|
||||
.uri(uri)
|
||||
.body(Body::from(body))
|
||||
.expect("Failed to create POST request");
|
||||
let resp = client.request(req).await.expect("Failed to POST");
|
||||
|
||||
println!("Response: {}", resp.status());
|
||||
|
||||
|
|
Loading…
Reference in New Issue