xh是一个友好且快速的发送 HTTP 请求的工具。它尽可能多地重新实现了HTTPie 的优秀设计,重点是提高了性能。
curl -sfL https://raw.githubusercontent.com/ducaale/xh/master/install.sh | sh
操作系统 | 方法 | 命令 |
---|---|---|
任何 | 货物* | cargo install xh |
任何 | 胡贝尔 | huber install xh |
拱形Linux | 吃豆子 | pacman -S xh |
Debian 和 Ubuntu | 易于** | sudo apt install xh |
FreeBSD | 新鲜 Port | pkg install xh |
Linux 和 macOS | 尼克斯 | nix-env -iA nixpkgs.xh |
Linux 和 macOS | 家酿 | brew install xh |
苹果系统 | 端口 | sudo port install xh |
视窗 | 舀 | scoop install xh |
* 确保你安装了 Rust 1.46 或更高版本
** 你需要从https://apt.cli.rs/添加 apt 存储库
该版本页面包含适用于Linux,MacOS和的Windows预编译的二进制。
USAGE: xh [OPTIONS] <[METHOD] URL> [--] [REQUEST_ITEM]... OPTIONS: -j, --json (default) Serialize data items from the command line as a JSON object -f, --form Serialize data items from the command line as form fields -m, --multipart Like --form, but force a multipart/form-data request even without files --pretty <STYLE> Controls output processing [possible values: all, colors, format, none] -s, --style <THEME> Output coloring style [possible values: auto, solarized, monokai] --response-charset <ENCODING> Override the response encoding for terminal display purposes --response-mime <MIME_TYPE> Override the response mime type for coloring and formatting for the terminal -p, --print <FORMAT> String specifying what the output should contain -h, --headers Print only the response headers, shortcut for --print=h -b, --body Print only the response body, Shortcut for --print=b -v, --verbose Print the whole request as well as the response --all Show any intermediary requests/responses while following redirects with --follow -P, --history-print <FORMAT> The same as --print but applies only to intermediary requests/responses -q, --quiet Do not print to stdout or stderr -S, --stream Always stream the response body -o, --output <FILE> Save output to FILE instead of stdout -d, --download Download the body to a file instead of printing it -c, --continue Resume an interrupted download. Requires --download and --output --session <FILE> Create, or reuse and update a session --session-read-only <FILE> Create or read a session without updating it form the request/response exchange -A, --auth-type <auth-type> Specify the auth mechanism [possible values: basic, bearer, digest] -a, --auth <USER[:PASS] | TOKEN> Authenticate as USER with PASS or with TOKEN --ignore-netrc Do not use credentials from .netrc --offline Construct HTTP requests without sending them anywhere --check-status (default) Exit with an error status code if the server replies with an error -F, --follow Do follow redirects --max-redirects <NUM> Number of redirects to follow, only respected if `follow` is set --timeout <SEC> Connection timeout of the request --proxy <PROTOCOL:URL>... Use a proxy for a protocol. For example: `--proxy https:http://proxy.host:8080` --verify <VERIFY> If "no", skip SSL verification. If a file path, use it as a CA bundle --cert <FILE> Use a client side certificate for SSL --cert-key <FILE> A private key file to use with --cert --ssl <VERSION> Force a particular TLS version [possible values: auto, ssl2.3, tls1, tls1.1, tls1.2, tls1.3] --native-tls Use the system TLS library instead of rustls (if enabled at compile time) --https Make HTTPS requests if not specified in the URL --http-version <VERSION> HTTP version to use [possible values: 1, 1.0, 1.1, 2] -I, --ignore-stdin Do not attempt to read stdin --curl Print a translation to a `curl` command --curl-long Use the long versions of curl's flags --help Prints help information -V, --version Prints version information ARGS: <[METHOD] URL> The request URL, preceded by an optional HTTP method <REQUEST_ITEM>... Optional key-value pairs to be included in the request Each option can be reset with a --no-OPTION argument.
运行
xh help以获取更多详细信息。
xh使用HTTPie 的 request-item 语法来设置标头、请求正文、查询字符串等。
=/
:=用于设置请求正文的 JSON 或表单字段(
=用于字符串和
:=其他 JSON 类型)。
==用于添加查询字符串。
@用于在多部分请求中包含文件,例如
picture@hello.jpg或
picture@hello.jpg;type=image/jpeg;filename=goodbye.jpg。
:用于添加或删除标题,例如
connection:keep-alive或
connection:。
;用于包含具有空值的标题,例如
header-without-value;.
=@/
:=@用于设置请求正文的 JSON 或来自文件的表单字段(
=@用于字符串和
:=@其他 JSON 类型)。
请求正文也可以从标准输入或使用
@filename.
与 HTTPie 类似,指定请求 URL 的方案部分是可选的。
xh还支持
localhost从 URL 中省略,只要它以冒号开头加上一个可选的端口号。
xh http://localhost:3000/users # resolves to http://localhost:3000/users
xh localhost:3000/users # resolves to http://localhost:3000/users
xh :3000/users # resolves to http://localhost:3000/users
xh :/users # resolves to http://localhost:80/users
xh example.com # resolves to http://example.com
xh将默认使用HTTPS方案如果二进制名称是一个
xhs,
https或
xhttps。如果你是
xh通过包管理器安装的,则默认情况下应该可以使用
xh和
xhs。否则,你需要像这样创建一个:
cd /path/to/xh && ln -s ./xh ./xhs
xh httpbin.org/get # resolves to http://httpbin.org/get
xhs httpbin.org/get # resolves to https://httpbin.org/get
如果
xh被调用为
http或
https(通过重命名二进制文件),或者如果
XH_HTTPIE_COMPAT_MODE设置了环境变量,它将以 HTTPie 兼容模式运行。当前唯一的区别是
--check-status默认情况下未启用。
# Send a GET request
xh httpbin.org/json
# Send a POST request with body {"name": "ahmed", "age": 24}
xh httpbin.org/post name=ahmed age:=24
# Send a GET request with querystring id=5&sort=true
xh get httpbin.org/json id==5 sort==true
# Send a GET request and include a header named x-api-key with value 12345
xh get httpbin.org/json x-api-key:12345
# Send a PUT request and pipe the result to less
xh put httpbin.org/put id:=49 age:=25 | less
# Download and save to res.json
xh -d httpbin.org/json -o res.json
--curl标志的curl 命令的内置翻译。
--help. (对于更长的输出,通过
help。)
--check-status除非
xh在严格兼容模式下使用, 否则启用。
rustls默认使用 TLS 库而不是系统的 TLS 库。(如果在编译时启用,则
--native-tls可以使用该标志。)