requests常用請求方法使用,包括:get,post
requests庫中的Session、Cookie的使用
其它進階部分:認證、代理、證書驗證、逾時配置、錯誤異常處理等。
本節首先來了解一下requests庫中如何發送get請求:
一、看下方法定義:
python接口自動化測試(二)-requests.get() 2、點選右上角的【source】,看一下它的源碼如下:
python接口自動化測試(二)-requests.get() 3、HTTP協定是一個基于請求/響應模式的、無狀态的,應用層協定。既然有請求,就有響應,來看下resquest中常用的響應資訊:
python接口自動化測試(二)-requests.get() 二、get方法簡單使用:
1、不帶參數的get:
python接口自動化測試(二)-requests.get()
python接口自動化測試(二)-requests.get() 輸出:
python接口自動化測試(二)-requests.get()
python接口自動化測試(二)-requests.get() 2、 帶參數的get:
python接口自動化測試(二)-requests.get()
python接口自動化測試(二)-requests.get() 輸出:
python接口自動化測試(二)-requests.get()
python接口自動化測試(二)-requests.get() 3、帶header的get:
python接口自動化測試(二)-requests.get()
python接口自動化測試(二)-requests.get() 輸出:
4、同時帶參數和header:
python接口自動化測試(二)-requests.get()
python接口自動化測試(二)-requests.get() 本文轉自賀滿部落格園部落格,原文連結:http://www.cnblogs.com/puresoul/p/7488488.html,如需轉載請自行聯系原作者。