HTTP调试工具HTTPie

2017-01-19 17:33:50

HTTPie(读aych-tee-tee-pie)是一个 HTTP 的命令行客户端,其目标是让 CLI 和 web 服务之间的交互尽可能的人性化.
HTTPie 采用 Python 开发,底层用到了 Requests 和 Pygments 库,缺省支持json,比curl的语法更加简洁.

安装

1
2
3
4
5
6
#Debian,Ubuntu 或者 Linux Mint:
sudo apt-get install httpie
#linux
pip install httpie
#centos7
yum -y install python2-httpie.noarch

用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#simulation commit a form
http -f POST iweishao.com username=neo

#display more detailed request
http -v iweishao.com

#display Header
http -h iweishao.com

#display Body
http -b iweishao.com

#download file
http -d iweishao.com

#request a delete method
http DELETE iweishao.com

#pass json data request(default json request)
http PUT iweishao.com name=neo password=neo_password
#if json data not string use := to serperate,eg
http PUT iweishao.com name=neo password=neo_password age:=28 a:=true streets:='["a","b"]'

#simulation Form Post method,Content-Type: application/x-www-form-urlencoded; charset=utf-8
http --form POST iweishao.com name='neo'

#simulation Form upload,Content-Type: multipart/form-data
http -f POST iweishao.com/jobs name='neo' file@~/test.pdf

#modify request header,use : serperate
http iweishao.com User-Agent:Yhz/1.0 'Cookie:a=b;b=c' Referer:http://iweishao.com/

#auth
http -a username:password iweishao.com
http --auth-type=digest -a username:password iweishao.com

#use http proxy
http --proxy=http:http://192.168.1.130:8060 iweishao.com
http --proxy=http:http://user:pass@192.168.1.130:8060 iweishao.com

高级用法:

1
2
3
4
5
6
7
8
9
10
11
12
# display all and direct
http --all --follow iweishao.com/redirect/3

#download binary file
http example.org/movie.mov >mov.mov

#download image,use Imagemagick convert, upload another website
http octodex.example.com/images/original.jpg |convert - -resize 25% - | http iweishao/Octocats
# put auth info to session
http --session=user1 -a user:password example.org X-foo:Bar
#use before auth session visite
http --session=user example.org


您的鼓励是我写作最大的动力

俗话说,投资效率是最好的投资。 如果您感觉我的文章质量不错,读后收获很大,预计能为您提高 10% 的工作效率,不妨小额捐助我一下,让我有动力继续写出更多好文章。