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 GET request. 17 18 use ylong_http_client::async_impl::{Client, Downloader}; 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 // Customizes your HTTP request. 27 let request = Request::builder() 28 .method(Method::GET) 29 .url("http://www.example.com") 30 .body("".as_bytes()) // EmptyBody 31 .unwrap(); 32 33 // Sends your HTTP request through the client. 34 let response = client.request(request).await.unwrap(); 35 36 // Uses `Downloader` to download the response body and display message on console. 37 let _ = Downloader::console(response).download().await; 38 } 39