6、http客户端httpie工具

来源:互联网 发布:万方数据库中检索字段 编辑:程序博客网 时间:2024/06/05 02:41

HTTPie (读aych-tee-tee-pie)是一个 HTTP 的命令行客户端。其目标是让 CLI 和 web 服务之间的交互尽可能的人性化。

下载链接

https://github.com/jakubroztocil/httpie 

进入目录中然后执行安装

安装

python setup.py install

使用

模拟提交表单

http -f POST www.baidu.com username=zych

HTTP/1.1302 Moved Temporarily

BDPAGETYPE: 3

Connection: Keep-Alive

Content-Length: 215

Content-Type: text/html

Date: Wed, 12 Apr 2017 14:29:17 GMT

Location: http://www.baidu.com/search/error.html

Server: BWS/1.1

Set-Cookie: BDSVRTM=0; path=/

X-UA-Compatible: IE=Edge,chrome=1


<html>

<head><title>302 Found</title></head>

<body bgcolor="white">

<center><h1>302 Found</h1></center>

<hr><center>pr-nginx_1-0-331_BRANCH Branch

Time : Mon Apr 10 17:34:12 CST 2017</center>

</body>

</html>

显示详细的请求

http -v www.baidu.com

只显示Header

http -h www.baidu.com

$ http -h www.baidu.com

HTTP/1.1200 OK

BDPAGETYPE: 1

BDQID: 0xe10ae381000759e7

BDUSERID: 0

Cache-Control: private

Connection: Keep-Alive

Content-Encoding: gzip

Content-Type: text/html; charset=utf-8

Cxy_all: baidu+6ca6e88fd93a50a732b9798478fd7f0b

Date: Wed, 12 Apr 2017 14:55:19 GMT

Expires: Wed, 12 Apr 2017 14:54:20 GMT

P3P: CP=" OTI DSP COR IVA OUR IND COM "

Server: BWS/1.1

Set-Cookie: BAIDUID=57D3B51A231F2A17856F0A3F4B9064DD:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com

Set-Cookie: BIDUPSID=57D3B51A231F2A17856F0A3F4B9064DD; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com

Set-Cookie: PSTM=1492008919; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com

Set-Cookie: BDSVRTM=0; path=/

Set-Cookie: BD_HOME=0; path=/

Set-Cookie: H_PS_PSSID=1463_21093_18560_20930; path=/; domain=.baidu.com

Transfer-Encoding: chunked

Vary: Accept-Encoding

X-Powered-By: HPHP

X-UA-Compatible: IE=Edge,chrome=1


只显示Body

http -b www.baidu.com

下载文件

http -d www.baidu.com

会把百度首页下载到当前目录中

请求删除的方法

http DELETE www.baidu.com

传递JSON数据请求(默认就是JSON数据请求)

http PUT www.baidu.com name=nate password=nate_password

如果JSON数据存在不是字符串则用:=分隔,例如

http PUT www.baidu.com name=nate password=nate_password age:=28 a:=true streets:='["a", "b"]'

模拟Form的Post请求, Content-Type: application/x-www-form-urlencoded; charset=utf-8

http --form POST www.baidu.com name='nate'

模拟Form的上传, Content-Type: multipart/form-data

http -f POST example.com/jobs name='John Smith' file@~/test.pdf

修改请求头, 使用:分隔

http www.baidu.com  User-Agent:badman/1.0  'Cookie:a=b;b=c'  Referer:https://www.baidu.com/

认证

http -a username:password www.baidu.com

http --auth-type=digest -a username:password www.baidu.com

使用http代理

http --proxy=http:http://192.168.1.100:8060 www.baidu.com

http --proxy=http:http://user:pass@192.168.1.100:8060 www.baidu.com

0 0