天天看點

httpie子產品的詳細介紹和使用

【背景知識】

你一定聽過或者用過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. 通路一個網站 但想要顔色分明

【指令幫助資訊】

用法

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   

<a href="http://s1.51cto.com/wyfs02/M02/7F/B8/wKiom1cqABLhWcjlAACd_MPaFMI572.png" target="_blank"></a>

2 隻傳回請求頭部

http --print H www.baidu.com

<a href="http://s1.51cto.com/wyfs02/M01/7F/B6/wKioL1cqAUzC23_GAAAaf9ql-QU891.png" target="_blank"></a>

3 POST的使用等具體調用api的時候在講解

http example.org hello=world   # =&gt; 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

<a href="http://s4.51cto.com/wyfs02/M01/7F/B6/wKioL1cqBE2SBwxrAAAklVzHkxM748.png" target="_blank"></a>

本文轉自殘劍部落格51CTO部落格,原文連結http://blog.51cto.com/cuidehua/1770191如需轉載請自行聯系原作者

cuizhiliang