http 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

http 命令安装:


-bash/zsh: http/httpie: command not found

#Snapcraft (Linux)
snap install httpie

#Debian
apt-get install httpie

#Ubuntu
apt-get install httpie

#Alpine
apk add httpie

#Arch Linux
pacman -S httpie

#Kali Linux
apt-get install httpie

#Fedora
dnf install httpie

#FreeBSD
pkg install www/py-httpie

#CentOS and RHEL
yum install epel-release
yum install httpie

#OS X
brew install httpie

#Raspbian
apt-get install httpie

#Windows
choco install httpie
choco upgrade httpie

#Docker
docker run cmd.cat/http http

http 命令补充说明:


HTTPie(发音:aitch-tee-tee-pie): 是一个 HTTP 的客户端,用户友好的 cURL 替代品。

HTTPie 让 API 变得简单,它的目标是使 CLIWeb 服务的交互尽可能人性化。 HTTPie 设计用于测试、调试以及通常与 API 和 HTTP 服务器交互。 http 和 https 命令允许创建和发送任意 HTTP 请求。 它们使用简单自然的语法,并提供格式化和彩色输出。

HTTPie Descktop 桌面客户端

http 命令特性:


  • 富有表现力和直观的语法
  • 格式化和彩色终端输出
  • 内置 JSON 支持
  • 表格和文件上传
  • HTTPS、代理和身份验证
  • 任意请求数据
  • 自定义标题
  • 持续会话
  • 类似 Wget 的下载
  • Linux、macOS、Windows 和 FreeBSD 支持
  • 插件
  • 文档
  • 测试覆盖率

http 命令语法:


http [flags] [METHOD] URL [ITEM [ITEM]]
http [--json] [--form] [--multipart] [--boundary BOUNDARY] [--raw RAW]

http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
            [--all] [--history-print WHAT] [--stream] [--output FILE]
            [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest}]
            [--proxy PROTOCOL:PROXY_URL] [--follow]
            [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
            [--check-status] [--verify VERIFY]
            [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
            [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
            [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
            [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]

http 命令选项:


- GET for requests without body
- POST for requests with body

http 命令实例:


http / httpie 下载文件的 URL:

http -d example.org

http / httpie 发送表单编码数据:

http -f example.org name='bob' profile_picture@'bob.png'

http / httpie 发送 JSON 对象:

http example.org name='bob'

http / httpie 指定 HTTP 方法:

http HEAD example.org

http / httpie 包括一个额外的标题:

http example.org X-MyHeader:123

http / httpie 传递用户名和密码进行服务器认证:

http -a username:password example.org

http / httpie 通过标准输入指定原始请求正文:

cat data.txt | http PUT example.org

http 命令扩展阅读:




http 命令评论