httpie模块的详细介绍和使用
2016-05-04 22:13
447 查看
【背景知识】
你一定听过或者用过htop 和pssh pscp等用python实现linux当中的top ssh scp 功能的加强! python写的不仅共鞥强,而且有颜色分辨且选项说明和详细!文档比较规范
【httpie模块的安装】
pip install httpie
使用范围python 2.6 2.7 和python 3中都可以使用
安装之后生成http命令提供使用(在linux sheel中经常用curl 和wget 进行完成日常的工作)
【使用环境】
a. 调试api接口
b. 访问一个网站 但想要颜色分明
【命令帮助信息】
用法
http <请求方法如 HEAD> <url 如www.baidu.com> <请求的头部选项如 User-Agent:bacon/1.0>
Output Options:
--print WHAT, -p WHAT
String specifying what the output should contain:
'H' request headers
'B' request body
'h' response headers
'b' response body
模式输出是 hb 返回响应头部和响应body
Predefined Content Types:
--json, -j
(default) Data items from the command line are serialized as a JSON object.
The Content-Type and Accept headers are set to application/json
(if not specified).
--form, -f
Data items from the command line are serialized as form fields.
The Content-Type is set to application/x-www-form-urlencoded (if not
specified). The presence of any file fields results in a
multipart/form-data request.
一般会使用-f
【命令基本使用】
1 只返回响应头部
http --print h
等于
http HEAD www.baidu.com
等于
curl -I http:://www.baidu.com
2 只返回请求头部
http --print H www.baidu.com
3 POST的使用等具体调用api的时候在讲解
http example.org hello=world # => POST
4 改变请求头部
REQUEST_ITEM 修改的请求项目一定要放在最后面!
4.1修改user-agent()
http --print H http://www.baidu.com User-Agent:bacon/1.0
4.2 将参数附加到url后面作为参数请求
'==' URL parameters to be appended to the request URI:
http --print H http://www.baidu.com?name=andy User-Agent:bacon/1.0
等于
http --print H http://www.baidu.com User-Agent:bacon/1.0 name==andy
本文出自 “崔德华运维打工从业路” 博客,请务必保留此出处http://cuidehua.blog.51cto.com/5449828/1770191
你一定听过或者用过htop 和pssh pscp等用python实现linux当中的top ssh scp 功能的加强! python写的不仅共鞥强,而且有颜色分辨且选项说明和详细!文档比较规范
【httpie模块的安装】
pip install httpie
使用范围python 2.6 2.7 和python 3中都可以使用
安装之后生成http命令提供使用(在linux sheel中经常用curl 和wget 进行完成日常的工作)
【使用环境】
a. 调试api接口
b. 访问一个网站 但想要颜色分明
【命令帮助信息】
用法
http <请求方法如 HEAD> <url 如www.baidu.com> <请求的头部选项如 User-Agent:bacon/1.0>
Output Options:
--print WHAT, -p WHAT
String specifying what the output should contain:
'H' request headers
'B' request body
'h' response headers
'b' response body
模式输出是 hb 返回响应头部和响应body
Predefined Content Types:
--json, -j
(default) Data items from the command line are serialized as a JSON object.
The Content-Type and Accept headers are set to application/json
(if not specified).
--form, -f
Data items from the command line are serialized as form fields.
The Content-Type is set to application/x-www-form-urlencoded (if not
specified). The presence of any file fields results in a
multipart/form-data request.
一般会使用-f
【命令基本使用】
1 只返回响应头部
http --print h
等于
http HEAD www.baidu.com
等于
curl -I http:://www.baidu.com
2 只返回请求头部
http --print H www.baidu.com
3 POST的使用等具体调用api的时候在讲解
http example.org hello=world # => POST
4 改变请求头部
REQUEST_ITEM 修改的请求项目一定要放在最后面!
4.1修改user-agent()
http --print H http://www.baidu.com User-Agent:bacon/1.0
4.2 将参数附加到url后面作为参数请求
'==' URL parameters to be appended to the request URI:
http --print H http://www.baidu.com?name=andy User-Agent:bacon/1.0
等于
http --print H http://www.baidu.com User-Agent:bacon/1.0 name==andy
本文出自 “崔德华运维打工从业路” 博客,请务必保留此出处http://cuidehua.blog.51cto.com/5449828/1770191
相关文章推荐
- 通信协议:HTTP、TCP、UDP
- 【arduino】通过Esp8266-01模块实现的WiFi通信(3)使用TCP协议进行局域网通信(client篇)
- Fiddler Https出现 no root certificate was found的解决方法
- Android使用HttpClient请求网络上的数据
- swift开发网络篇—利用NSURLConnection GET请求和POST请求
- Android使用HttpUriContion解析网络上请求的文件
- ICMP(网络控制信息协议 internet control message protocol)
- 深入理解http协议
- web学习笔记-httpServletResponse一
- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure
- 获取网络图片实现网络轮播
- C++网络爬虫的实现——WinSock编程
- swift开发网络篇 - post 请求
- httpd配置详解
- 4538: [Hnoi2016]网络 链剖 + 堆(优先队列) / 整体二分
- TCP/IP——TCP协议中提高网络利用率的机制
- ubuntu网络
- 判断有没有网络
- HTTP各个状态返回值
- Android学习记录(十二) http之base/digest鉴权。