# 4.2.requests

* 1.requests module
  * methods
    * reuests.get
    * reuests.post
    * reuests.put
    * reuests.delete
  * HTTP狀態碼:
    * [https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81](https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81)
  * REST API
    * [https://zh.wikipedia.org/wiki/REST](https://zh.wikipedia.org/wiki/REST)
* 2.Install **request** module
  *   [http://docs.python-requests.org/zh\_CN/latest/user/install.html#install](http://docs.python-requests.org/zh_CN/latest/user/install.html#install)

      ```
        git clone git://github.com/kennethreitz/requests.git
        python setup.py install
      ```
* 3.GET
  * 1.發送請求
    *   響應內容, JSON響應內容, 狀態碼

        ![](https://github.com/jenhsuan/python/tree/8fc9c0b8df4ccd709d3078c2d8842af0932de09d/assets/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202017-03-18%20%E4%B8%8B%E5%8D%8810.57.04.png)
  *   2.在header中加入參數

      ```
        import requests
        url = 'http://10.144.5.183/api/v1/devices'
        t = '$2a$10$RqOyphofSoIOwO8mbhEXfOYIX7ZkjrFUyrEPsJ4yzRzvRq/u'
        h = {'api-token': t}
        r = requests.get(url, headers=h)
        print r.text
      ```
