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 |
อัลไพน์ลินุกซ์ | apk *** | apk add xh |
ซุ้มประตู | คนแพคแมน | pacman -S xh |
Debian & Ubuntu | Apt **** | sudo apt install xh |
FreeBSD | นักกีฬา | pkg install xh |
netbsd | pkgsrc | pkgin install xh |
Linux & MacOS | nixpkgs | nix-env -iA nixpkgs.xh |
Linux & MacOS | การลอยตัว | flox install xh |
Linux & MacOS | โฮมบรูว์ | brew install xh |
Linux & MacOS | ฤาษี | hermit install xh |
แม็กอส | MacPorts | sudo port install xh |
หน้าต่าง | ตัก | scoop install xh |
หน้าต่าง | ช็อคโกแลต | choco install xh |
หน้าต่าง | ปีก | winget add ducaale.xh |
* ตรวจสอบให้แน่ใจว่าคุณติดตั้ง Rust 1.74 หรือใหม่กว่า
** คุณจะต้องติดตั้ง MMRL CLI
*** แพ็คเกจ XH มีอยู่ในขอบและจะอยู่ใน v3.17+ มันถูกสร้างขึ้นด้วย Native-TLS เท่านั้น
**** คุณจะต้องเพิ่มที่เก็บ apt จาก https://apt.cli.rs/
หน้ารีลีสมีไบนารี prebuilt สำหรับ 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 ในการตั้งค่าส่วนหัว, ตัวตนขอ, สตริงการสืบค้น ฯลฯ
=
/ :=
สำหรับการตั้งค่าฟิลด์ JSON หรือฟอร์มของร่างกายคำขอ ( =
สำหรับสตริงและ :=
สำหรับประเภท JSON อื่น ๆ )
==
สำหรับการเพิ่มสตริงแบบสอบถาม
@
สำหรับการรวมไฟล์ในคำขอหลายส่วนเช่น [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 เป็น 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
XH http: // localhost: 3000/ผู้ใช้ # แก้ไขให้เป็น http: // localhost: 3000/usersxh localhost: 3000/ผู้ใช้ # แก้ไขให้กับ http: // localhost: 3000/usersxh: 3000/ผู้ใช้ # localhost: 3000/usersxh:/ผู้ใช้ # แก้ไขให้เป็น http: // localhost: 80/usersxh example.com # แก้ไขเพื่อ http: //example.comxh: //example.com # แก้ไขให้ http://example.com
xh
จะเริ่มต้นเป็นโครงการ HTTPS หากชื่อไบนารีเป็นหนึ่งใน xhs
, https
หรือ xhttps
หากคุณติดตั้ง xh
ผ่านตัวจัดการแพ็คเกจทั้ง xh
และ xhs
ควรใช้งานได้ตามค่าเริ่มต้น มิฉะนั้นคุณต้องสร้างแบบนี้:
cd/path/to/xh && ln -s ./xh ./xhs XH httpbin.org/get # แก้ไขเป็น http://httpbin.org/getxhs httpbin.org/get # แก้ไขเพื่อ https://httpbin.org/get
หาก xh
ถูกเรียกใช้เป็น http
หรือ https
(โดยการเปลี่ยนชื่อไบนารี) หรือหากตั้งค่าตัวแปรสภาพแวดล้อม XH_HTTPIE_COMPAT_MODE
ตัวแปรจะถูกตั้งค่าจะทำงานในโหมดความเข้ากันได้ของ HTTPIE ความแตกต่างในปัจจุบันเพียงอย่างเดียวคือ --check-status
ไม่ได้เปิดใช้งานโดยค่าเริ่มต้น
# ส่ง get requestxh httpbin.org/json# ส่งคำขอโพสต์พร้อมร่างกาย {"ชื่อ": "ahmed", "อายุ": 24} xh httpbin.org/post name = Ahmed อายุ: = 24# ส่งคำขอรับ ด้วย querystring id = 5 & sort = truexh รับ httpbin.org/json id == 5 sort == true# ส่งคำขอรับและรวมส่วนหัวชื่อ X-Api-key ที่มีค่า 12345xh รับ httpbin.org/json x-Api-Api-key : 12345# ส่งคำขอโพสต์พร้อมกับร่างกายอ่านจาก stdin.echo "[1, 2, 3]" | XH โพสต์ httpbin.org/post# ส่งคำขอใส่และท่อผลลัพธ์ไปที่ lessxh ใส่ httpbin.org/put id: = 49 อายุ: = 25 | น้อยลง# ดาวน์โหลดและบันทึกไปยัง res.jsonxh -d httpbin.org/json -o res.json# ทำคำขอด้วย Agentxh ผู้ใช้ที่กำหนดเอง httpbin.org/get user-agent: foobar
ปรับปรุงความเร็วเริ่มต้น
มีให้เป็นไบนารีที่เชื่อมโยงกันแบบสแตติกเดียวซึ่งง่ายต่อการติดตั้งและพกพา
การสนับสนุน HTTP/2
การแปลในตัวเป็นคำสั่ง Curl ด้วยธง --curl
สั้น, เอาท์พุทสไตล์ Cheatsheet จาก --help
(สำหรับผลลัพธ์ที่ยาวนานขึ้นให้ผ่าน help
)
คุณสมบัติของ Httpie ทั้งหมดไม่ได้ถูกนำมาใช้ (#4)
ไม่มีระบบปลั๊กอิน
ความไม่สมบูรณ์ทั่วไป Httpie เก่าและผ่านการทดสอบอย่างดี
เอกสารที่แย่ลง
CURLIE - ส่วนหน้าไปยังม้วนที่เพิ่มความสะดวกในการใช้ httpie
httpie-go-ไคลเอนต์ http-like httpie เขียนใน GO
curl2httpie - แปลงอาร์กิวเมนต์คำสั่งระหว่าง curl และ httpie