httpie/xh 与 curl 对比
xh 相当于是 rust 版的 httpie(httpie 是 python 写的)
安装 xh
https://github.com/ducaale/xh?tab=readme-ov-file#via-a-package-manager
cargo install xh --lockeded
GET
curl https://httpbin.org/get?hello=world
xh httpbin.org/get hello==world # xh 默认请求 http
xhs httpbin.org/get hello==world # xhs 默认请求 https
POST
string/raw
curl -X POST -H 'content-type: text/plain' -d 'hello world' httpbin.org/post
xh httpbin.org/post --raw 'hello world'
xh post httpbin.org/post --raw 'hello world' # 显式 post
xh httpbin.org/post content-type:application/json --raw '["hello", "world"]'
json
curl -X POST -H 'content-type: application/json' -H 'fuck:you' -d '{"hello":"world"}' httpbin.org/post
xh httpbin.org/post fuck:you hello=world
用 =
分割的都是 string,对于其它类型如 boolean/number/object/array 的数据,要用 :=
分割
xh httpbin.org/post hello=world items:='["apple", "orange"]' is_handsome:=true age:=34 hobbies:='{"tool":"xh"}'
嵌套 json
post json array
xh httpbin.org/post []=hello []=world []:=true
form
curl -X POST -d hello=world httpbin.org/post
xh --form httpbin.org/post hello=world
查看请求内容,但不真的发送出去
xh --offline httpbin.org/post hello=world
+V why_null 请备注:from博客园