HTTPie 是一个 HTTP 的命令行客户端,目标是让 CLI 和 web 服务之间的交互尽可能的人性化。这个工具提供了简洁的 http 命令,允许通过自然的语法发送任意 HTTP 请求数据,展示色彩化的输出。HTTPie 是用 Python 编写,用到了 Requests 和 Pygments 这些出色的库。
Github:https://github.com/jakubroztocil/httpie
Windows
pip install --upgrade httpie
Mac OSX
brew install httpie
Linux
easy_install httpie
# Debian Ubuntu
apt-get install httpie
# Fedora CentOS RHEL
yum install httpie
# Arch Linux
pacman -S httpie
PS C:\Users\adley> http
usage: http [--json] [--form] [--multipart] [--boundary BOUNDARY] [--raw RAW] [--compress]
[--pretty {all,colors,format,none}] [--style STYLE] [--unsorted] [--sorted]
[--format-options FORMAT_OPTIONS] [--print WHAT] [--headers] [--body] [--verbose] [--all]
[--history-print WHAT] [--stream] [--output FILE] [--download] [--continue] [--quiet]
[--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH] [--auth USER[:PASS]]
[--auth-type {basic,digest}] [--ignore-netrc] [--offline] [--proxy PROTOCOL:PROXY_URL] [--follow]
[--max-redirects MAX_REDIRECTS] [--max-headers MAX_HEADERS] [--timeout SECONDS] [--check-status]
[--path-as-is] [--chunked] [--verify VERIFY] [--ssl {ssl2.3,tls1,tls1.1,tls1.2}] [--ciphers CIPHERS]
[--cert CERT] [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version] [--traceback]
[--default-scheme DEFAULT_SCHEME] [--debug]
[METHOD] URL [REQUEST_ITEM ...]
# 1 基本使用
http https://www.baidu.com
# 2 显示详情的请求,包含请求和响应
http -v http://httpbin.org/get?a=1
# 3 只显示Header(应该是响应头)
http -h http://httpbin.org/get?a=1
http --head http://httpbin.org/get?a=1
http --header http://httpbin.org/get?a=1
http --headers http://httpbin.org/get?a=1
# 4 只显示body
http -b http://httpbin.org/get?a=1
http -body http://httpbin.org/get?a=1
# 5 下载文件
http -d http://httpbin.org/get?a=1
# 6 模拟提交表单
http -f POST mimvp.com username='mimvp-user'
# 7 传递JSON数据请求(默认就是JSON数据请求)
http PUT mimvp.com username='mimvp-user' password='mimvp-pwd'
# 8 模拟Form的Post请求, Content-Type: application/x-www-form-urlencoded; charset=utf-8
http --form POST mimvp.com username='mimvp-user'
# 模拟Form的上传, Content-Type: multipart/form-data
http -f POST example.com/jobs username='mimvp-user' file@~/test.pdf
# 修改请求头, 使用:分隔
http mimvp.com User-Agent:mimvp-agent/1.0 'Cookie:a=b;b=c' Referer:http://mimvp.com/
# 认证
http -a username:password mimvp.com
http --auth-type=digest -a username:password mimvp.com
# 使用http代理
http --proxy=http:http://217.107.197.174:8081 proxy.mimvp.com
http --proxy=http:http://user:pass@217.107.197.174:8081 proxy.mimvp.com
http --proxy=https:http://112.114.96.34:8118 proxy.mimvp.com
http --proxy=https:http://user:pass@112.114.96.34:8118 proxy.mimvp.com