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之間的轉換命令參數