xh
是用于发送HTTP请求的友好而快速的工具。它尽可能地重新实现HTTPIE出色的设计,重点是改善性能。
curl -sfL https://raw.githubusercontent.com/ducaale/xh/master/install.sh | sh
iwr -useb https://raw.githubusercontent.com/ducaale/xh/master/install.ps1 | iex
操作系统 | 方法 | 命令 |
---|---|---|
任何 | 货物* | cargo install xh --locked |
任何 | 休伯 | huber install xh |
Android(termux) | PKG | pkg install xh |
Android(Magisk/kernelsu) | mmrl ** | mmrl install xhhttp |
高山Linux | apk *** | apk add xh |
Arch Linux | 帕克曼 | pacman -S xh |
Debian&Ubuntu | 易于**** | sudo apt install xh |
freebsd | Freshports | pkg install xh |
Netbsd | PKGSRC | pkgin install xh |
Linux&MacOS | nixpkgs | nix-env -iA nixpkgs.xh |
Linux&MacOS | Flox | flox install xh |
Linux&MacOS | 自制 | brew install xh |
Linux&MacOS | 隐士 | hermit install xh |
macos | Macports | sudo port install xh |
视窗 | 舀 | scoop install xh |
视窗 | 巧克力 | choco install xh |
视窗 | Winget | winget add ducaale.xh |
*确保您安装了1.74或以后生锈
**您需要安装MMRL CLI
*** XH软件包可在Edge中使用,将在v3.17+中。它仅使用本机-TL构建。
****您需要从https://apt.cli.rs/添加APT存储库
发布页面包含用于Linux,MacOS和Windows的预制二进制文件。
Usage: xh [OPTIONS] <[METHOD] URL> [REQUEST_ITEM]... Arguments: <[METHOD] URL> The request URL, preceded by an optional HTTP method [REQUEST_ITEM]... Optional key-value pairs to be included in the request. 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 --multipart Like --form, but force a multipart/form-data request even without files --raw <RAW> Pass raw request data without extra processing --pretty <STYLE> Controls output processing [possible values: all, colors, format, none] --format-options <FORMAT_OPTIONS> Set output formatting options -s, --style <THEME> Output coloring style [possible values: auto, solarized, monokai, fruity] --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 -m, --meta Print only the response metadata. Shortcut for --print=m -v, --verbose... Print the whole request as well as the response --debug Print full error stack traces and debug log messages --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 (-A basic|digest) or with TOKEN (-A bearer) --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 used --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, tls1, tls1.1, tls1.2, tls1.3] --https Make HTTPS requests if not specified in the URL --http-version <VERSION> HTTP version to use [possible values: 1.0, 1.1, 2, 2-prior-knowledge] --resolve <HOST:ADDRESS> Override DNS resolution for specific domain to a custom IP --interface <NAME> Bind to a network interface or local IP address -4, --ipv4 Resolve hostname to ipv4 addresses only -6, --ipv6 Resolve hostname to ipv6 addresses only -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 Print help -V, --version Print version Each option can be reset with a --no-OPTION argument.
运行xh help
以获取更多详细信息。
xh
使用HTTPIE的Request-Item语法来设置标题,请求正文,查询字符串等。
=
/ :=
用于设置请求主体的JSON或表单字段( =
字符串和:=
其他JSON类型)。
==
用于添加查询字符串。
@
对于在Multipart请求中包含文件eg [email protected]
或[email protected];type=image/jpeg;filename=goodbye.jpg
。
:
用于添加或删除标头,例如connection:keep-alive
或connection:
。
;
用于包含空值的标题,例如header-without-value;
。
@
前缀可用于从文件中读取值。例如: x-api-key:@api-key.txt
。
请求主体也可以从标准输入或使用@filename
的文件中读取。
要构建一个复杂的JSON对象,可以将JSON路径用作关键EG app[container][0][id]=090-5
。有关此语法的更多信息,请参阅https://httpie.io/docs/cli/nested-json。
与HTTPIE类似,指定请求URL的方案部分是可选的,并且领先的结肠可作为Localhost的速记。 :8000
等于localhost:8000
,并且:/path
等效于localhost/path
。
URL可以具有领先://
允许将URL快速转换为有效的XH或HTTPIE命令。例如, http ://httpbin.org/json
http://httpbin.org/json
成为http://httpbin.org/json。
XH http:// localhost:3000/用户#解析到http:// localhost:3000/usersxh localhost:3000/users#resolves to http:// localHost:3000/usersxh:3000/users#supers users#Resolves to http:// http://///// localhost:3000/userxh:/users#解析到http:// localhost:80/usersxh example.com#解析到http://example.comxh://example.com#resolves#resolves to http://example.com
如果二进制名称是xhs
, https
或xhttps
之一, xh
将默认为HTTPS方案。如果您已经通过软件包管理器安装了xh
,则默认情况下应提供xh
和xhs
。否则,您需要创建这样的人:
cd/path/to/xh && ln -s ./xh ./xhs XH httpbin.org/get#解决到http://httpbin.org/getxhs httpbin.org/get#sesolves to https://httpbin.org/get
如果将xh
调用为http
或https
(通过重命名二进制),或者设置XH_HTTPIE_COMPAT_MODE
环境变量,则将以HTTPIE兼容模式运行。当前唯一的区别是--check-status
默认未启用。
#发送get requestxh httpbin.org/json#发送带有body {“ name”:“ ahmed”,“ age”的邮政请求:24} xh httpbin.org/post name = ahmed name = ahmed age = ahmed age:= 24#发送get请求使用querystring ID = 5 = 5&stort = truexh get httpbin.org/json id == 5 sort == true#发送get请求,并包括一个名为x-api-key的标题,带有值12345xH get httpbin.org/json x-api-key :12345#发送一个帖子请求,并带有从stdin.echo读取的正文“ [1,2,3]” | XH POST httpbin.org/post#发送put请求,并将结果送至lessxh put httpbin.org/put ID:= 49岁:= 25 |少#下载并保存到res.jsonxh -d httpbin.org/json -o res.json#使用自定义用户代理httpbin.org/get user-agent提出请求:foobar
提高的启动速度。
可作为单个静态链接的二进制,易于安装和随身携带。
HTTP/2支持。
用--curl
标志将其转换为卷曲命令。
简短的作弊表式输出--help
。 (对于更长的输出,通过help
。)
并非所有HTTPIE的功能都已实现。 (#4)
没有插件系统。
一般不成熟。 Httpie旧且经过良好测试。
更糟糕的文档。
curlie-卷曲的前端,增加了httpie的易用性
httpie-go-像httpie一样的http客户端
curl2httpie- curl和httpie之间的转换命令参数