我正在学习 Rust,并认为构建一个 CLI 来与 File.io API 共享文件会很方便。
为此,我尝试使用reqwest发送请求,如File.io 文档中所述:
# from file.io doc -> works fine
$ curl --data "text=this is a secret pw" https://file.io
> {"success":true,"key":"zX0Vko","link":"https://file.io/zX0Vko","expiry":"14 days"}
当我运行下面的代码时,我得到一个 400 响应。也许标题有问题?我试过查看 curl 文档以找出我可能遗漏的内容,但我很难过。
任何帮助,将不胜感激。
我的代码:
extern crate reqwest;
fn main() {
let client = reqwest::Client::new();
let res = client.post("https://file.io/")
.body("text=this is a practice run")
.send();
println!("{:?}", res);
}
预期反应:
{"success":true,"key":"SOME_KEY","link":"SOME_LINK","expiry":"14 days"}
实际反应:
Ok(Response { url: "https://file.io/", status: 400, headers: {"date": "Wed, 06 Feb 2019 03:40:35 GMT", "content-type": "application/json; charset=utf-8", "content-length": "64", "connection": "keep-alive", "x-powered-by": "Express", "x-ratelimit-limit": "5", "x-ratelimit-remaining": "4", "access-control-allow-origin": "*", "access-control-allow-headers": "Cache-Control,X-reqed-With,x-requested-with", "etag": "W/\"40-SEaBd3tIA9c06hg3p17dhWTvFz0\""} })