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

nested json

post json array

top level arrays

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

posted on 2024-07-06 16:28  明天有风吹  阅读(40)  评论(0编辑  收藏  举报

导航

+V atob('d2h5X251bGw=')

请备注:from博客园