HTTPie: a CLI, cURL-like tool for humans

HTTPie






github


HTTPie 是用 Python 编写,用到了 Requests 和 Pygments 这些出色的库。



主要特性:

  • 直观的语法
  • 格式化和色彩化的终端输出
  • 内置 JSON 支持
  • 支持上传表单和文件
  • HTTPS、代理和认证
  • 随意请求数据
  • 自己定义头部
  • 持久性会话
  • 类 Wget 下载
  • 支持 Python 2.6, 2.7 和 3.x
  • 支持 Linux, Mac OS X 和 Windows
  • 插件
  • 文档
  • 測试覆盖率

安装


Mac OS X

$ brew install httpie

Linux 

# Debian-based distributions such as Ubuntu:
$ apt-get install httpie

# RPM-based distributions:
$ yum install httpie

通过pip:

# Make sure we have an up-to-date version of pip and setuptools:
$ pip install --upgrade pip setuptools

$ pip install --upgrade httpie


使用

        

hello world

$ http httpie.org

http --help


參考手冊

https://pypi.python.org/pypi/httpie



样例

  • 自己定义HTTP方法,HTTP header和JSON数据

$ http PUT example.org X-API-Token:123 name=John

  • 提交表单

$ http -f POST example.org hello=World
  • 打印发送请求使用的输出项

$ http -v example.org
  • 利用使用Github API公布评论和验证一个问题

$ http -a USERNAME POST https://api.github.com/repos/jakubroztocil/httpie/issues/83/comments body='HTTPie is awesome!'
  • 使用重定向输入上传一个文件

$ http example.org < file.json
  • 下载一个文件并通过重定向输出将其保存

$ http example.org/file > file

  • wget风格下载文件

$ http --download example.org/file
  • 使用session保持请求同样的主机之间的通信
$ http --session=logged-in -a username:password httpbin.org/get API-Key:123

$ http --session=logged-in httpbin.org/headers
  • 设置一个自己定义的主机头工作在失踪的DNS记录:
$ http localhost:8000 Host:example.com

HTTP Method

HTTP 请求方法位于 URL的左边,以下是使用DELETE方法进行请求

$ http DELETE example.org/todos/7

就像运行了以下的request-line命令行

DELETE /todos/7 HTTP/1.1

HTTPie 默认使用 GET (with no request data) 或者 POST (with request data).

Request URL

 HTTPie 须要请求一个URL. 默认的 scheme 是 http://, 并且能够省略參数 – http , example.org就代表了 http://example.org,此外,支持curl类似的localhost, 比如  :3000 代表 http://localhost:3000, 默认是80port

$ http :/foo
GET /foo HTTP/1.1
Host: localhost
$ http :3000/bar
GET /bar HTTP/1.1
Host: localhost:3000
$ http :
GET / HTTP/1.1
Host: localhost

当手动在url中加入 querystring parameters , 能够直接使用 key==value key==value  的形式而不用操心 & 符号. 

$ http GET www.google.com search==HTTPie tbm==isch
GET /?

search=HTTPie&tbm=isch HTTP/1.1



 
原文地址:https://www.cnblogs.com/wzzkaifa/p/6918614.html