Explorar el Código

Only POST

lox-distributor requires POSTs, not GETs
Vecna hace 1 año
padre
commit
00b4e70c95
Se han modificado 1 ficheros con 8 adiciones y 13 borrados
  1. 8 13
      src/client_net.rs

+ 8 - 13
src/client_net.rs

@@ -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());