first working version
parent
38abdbfa75
commit
540ab15474
11
src/main.rs
11
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use hyper::{Body, Client, Method, Request, Response};
|
use hyper::{Body, Client, Method, Request, Response, body};
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use serde::ser;
|
use serde::ser;
|
||||||
|
|
||||||
|
@ -17,12 +17,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let request = Request::builder()
|
let request = Request::builder()
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.uri("https://api-free.deepl.com/v2/translate")
|
.uri("https://api-free.deepl.com/v2/translate?auth_key=7e47a305-561c-0a25-1e1a-ba929d96a88c:fx")
|
||||||
.header("content-type", "application/x-www-form-urlencoded")
|
.header("content-type", "application/x-www-form-urlencoded")
|
||||||
.body(Body::from(r#"{"library":"hyper"}"#))?;
|
.body(Body::from(r#"auth_key=7e47a305-561c-0a25-1e1a-ba929d96a88c:fx&text=Hello, world&target_lang=DE"#))?;
|
||||||
|
|
||||||
let res = client.request(request).await?;
|
let res = client.request(request).await?;
|
||||||
println!("{:?}", res.serialize());
|
let body_bytes = body::to_bytes(res.into_body()).await?;
|
||||||
assert_eq!(res.status(), 200);
|
let body = String::from_utf8(body_bytes.to_vec()).expect("response was not valid utf-8");
|
||||||
|
println!("Body: {}", body);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue