xh --multipart POST httpbin.org/post name=John file@doc.pdf
混合データを含むマルチパートフォーム
xh httpbin.org/get Cookie:session=abc123
クッキーを送信
xh --auth-type=digest -a user:pass httpbin.org/digest-auth/auth/user/pass
ダイジェスト認証
構文
タイプ
例
key=value
文字列
name=John → {"name":"John"}
key:=number
数字
age:=30 → {"age":30}
key:=true
ブール値
active:=true → {"active":true}
key:=null
Null
middle:=null → {"middle":null}
key:='[...]'
配列
tags:='["a","b"]' → {"tags":["a","b"]}
key:='{...}'
オブジェクト
meta:='{"v":1}' → {"meta":{"v":1}}
key[sub]=value
ネステッド
user[name]=John → {"user":{"name":"John"}}
# Linux/macOS~/.config/xh/sessions/# Windows%APPDATA%\xh\sessions\```## 設定### セッションストレージの場所```bash# Set default proxyexport HTTP_PROXY=http://proxy.example.com:8080export HTTPS_PROXY=http://proxy.example.com:8080# Disable proxy for specific hostsexport NO_PROXY=localhost,127.0.0.1,.example.com# Default timeoutexport XH_TIMEOUT=30```### 環境変数```bash# Add to ~/.bashrc or ~/.zshrc# HTTPie compatibilityalias http='xh'alias https='xh --default-scheme=https'# Quick shortcutsalias xhj='xh --pretty=all' # Force JSON pretty-printalias xhn='xh --pretty=none' # No formattingalias xhv='xh -v' # Verbose by defaultalias xhd='xh --download' # Download mode```### 一般的なエイリアス```bash# Login and save sessionxh --session=api POST https://api.example.com/login \ username=admin password=secret# Make authenticated requests using saved sessionxh --session=api GET https://api.example.com/users# Update resourcexh --session=api PUT https://api.example.com/users/123 \ name="John Doe" email=john@example.com status=active# Delete resourcexh --session=api DELETE https://api.example.com/users/123```## 一般的なユースケース### ユースケース:認証付きREST APIのテスト```bash# Upload file with additional form fieldsxh -f POST https://api.example.com/upload \ file@/path/to/document.pdf \ title="Important Document" \ category=legal \ tags:='["contract","2024"]'# Multiple file uploadxh -f POST https://api.example.com/batch-upload \ file1@image1.jpg \ file2@image2.jpg \ album="Vacation 2024"```### ユースケース:メタデータ付きファイルアップロード```bash# Development environmentxh --session=dev POST https://dev-api.example.com/test \ Authorization:"Bearer dev-token-123" \ data=test# Staging environmentxh --session=staging POST https://staging-api.example.com/test \ Authorization:"Bearer staging-token-456" \ data=test# Production environment (with SSL verification)xh --session=prod POST https://api.example.com/test \ Authorization:"Bearer prod-token-789" \ data=test```### ユースケース:異なる環境でのAPI テスト```bash# Capture webhook payload to filexh POST https://webhook.site/your-unique-url \ event=user.created \ user[id]:=12345 \ user[email]=new@example.com \ timestamp:=$(date +%s) \ -v -o webhook-debug.txt# Test webhook with retry logic (in script)for i in {1..3}; do xh POST https://your-app.com/webhook \ event=test \ attempt:=$i && break || sleep 5done```### ユースケース:Webhookペイロードのデバッグ```bash# Download JSON dataxh GET https://api.github.com/users/octocat/repos \ -o repos.json# Download with authentication and savexh -a token:ghp_your_token \ GET https://api.github.com/user/repos \ visibility==private \ -o private-repos.json# Stream large datasetxh --stream GET https://api.example.com/export/data \ format==json \ | jq '.[] | select(.active == true)' \ > active-records.json```### ユースケース:APIデータのダウンロードと処理`--session=name`セッション`:=`JSON型強制`age:=30`true`active:=true`false`xh POST api.com name=value`xh get https://api.example.com/users`-v`-vWould you like me to elaborate on any part of the translation?`xh -a token:secret_key`、使用`xh -a token:$API_TOKEN`を使用して、シェル履歴に資格情報を公開しないようにします。- **出力リダイレクションを活用する**: レスポンスを保存 `-o file.json`でCI/CDパイプラインや自動テストスクリプトでの処理や比較に使用します。- **適切なタイムアウトを設定する**: 遅いAPIに対して `--timeout=30`を使用してハングするリクエストを防ぎます。ストリーミングや長時間実行される操作に対してのみ `--timeout=0`を設定します。- **環境ごとにセッションを整理する**: 開発、ステージング、本番環境(`--session=prod-api`)用に別々のセッションを作成して、誤った資格情報を使用しないようにします。## トラブルシューティング| 問題 | ソリューション ||-------|----------|| `SSL certificate verification failed` | Use `--verify=no` to skip verification (insecure) or `--cert=/path/to/ca.pem` to provide custom CA certificate || `Connection timeout` | Increase timeout with `--timeout=60` or check network connectivity and proxy settings || `401 Unauthorized` | Verify authentication method: use `-a user:pass` for basic auth, `-A bearer -a token` for bearer tokens, or check session validity || `JSON parsing error` | Ensure proper syntax: use `:=` for non-strings (`age:=30`), quote arrays (`tags:='["a","b"]'`), and check for unescaped special characters || `Command not found: xh` | Verify installation path is in `$PATH`, reinstall using preferred method, or use full path `/usr/local/bin/xh` || `Session not persisting` | Check session directory permissions (`~/.config/xh/sessions/`), ensure using same session name, verify not using `--session-read-only` || `Proxy connection failed` | Verify proxy URL format `--proxy=http:http://host:port`, check proxy authentication if required, ensure proxy allows target host || `File upload fails` | Use `-f` or `--multipart` flag for form uploads, verify file path is correct, check file permissions and size limits || `Response not formatted/colored` | Force formatting with `--pretty=all`, check terminal supports colors, or pipe through `jq` for JSON formatting || `HTTP/2 not working`| サーバーがHTTP/2をサポートしているか確認し、OpenSSL/TLSが適切に設定されているか確認し、比較するために `--http-version=1.1`でHTTP/1.1を強制的に使用してみてください |
This site uses cookies for analytics and to improve your experience.
See our Privacy Policy for details.