一個Rust HttpClient例子
在cargo.toml文件中添加
[dependencies]
hyper = "0.7.2"
src中創建main.rs
extern crate hyper;
use std::io::Read;
use hyper::Client;
fn main() {
println!("welcome to rust http");
let client = Client::new();
let mut res = client.get(");
assert_eq!(res.status, hyper::Ok);
println!("headers:\n {}", res.headers);
let mut body = String::new();
res.read_to_string(&mut body).unwrap();
println!("body:\n {}", body);
res = client.post(");
assert_eq!(res.status, hyper::Ok);
println!("headers:\n {}", res.headers);
let mut body = String::new();
res.read_to_string(&mut body).unwrap();
println!("body:\n {}", body);
}</pre> 執行 cargo build 后執行 ./target/debug/項目名 即可看到效果。
</div>
</code></code>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!