| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
8年前发布

一个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("https://httpbin.org/get").send().unwrap();      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("https://httpbin.org/post").body("{\"a\":1}").send().unwrap();      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);  }

执行 cargo build 后执行 ./target/debug/项目名 即可看到效果。

来自: http://ipfans.github.io/2016/01/rust-http-client/

</code></code>

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!