1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 //! Uses an Asynchronous HTTP client to send a `POST` request. 17 18 use ylong_http_client::async_impl::{Client, Downloader, Uploader}; 19 use ylong_http_client::{Method, Request}; 20 21 #[tokio::main] main()22async fn main() { 23 // Customizes your HTTP client. 24 let client = Client::builder().build().unwrap(); 25 26 // Uses `Uploader` to upload the body and use `Console` to display messages on console. 27 let uploader = Uploader::builder() 28 .reader("HelloWorld".as_bytes()) 29 .console() 30 .build(); 31 32 // Customizes your HTTP request. 33 let request = Request::builder() 34 .method(Method::POST) 35 .url("https://www.example.com") 36 .body(uploader) 37 .unwrap(); 38 39 // Sends your HTTP request through the client. 40 let response = client.request(request).await.unwrap(); 41 42 // Uses `Downloader` to download the response body and display message on console. 43 let _ = Downloader::console(response).download().await; 44 } 45