接口自動化(八)--請求方式封裝

忘記了請求模塊,若是須要用到除post、get請求以外的請求方式直接照例定義到Methord類下json

 1 import requests
 2 import json
 3 
 4 class Methord():
 5     def runMethord(self,methord,url,data=None,headers=None):
 6         res = None
 7         if headers != None:
 8             if methord == "post":
 9                 res = requests.post(url,data,headers=headers)
10             elif methord == "get":
11                 res = requests.get(url,data,headers=headers)
12         else:
13             if methord == "post":
14                 res = requests.post(url,data)
15             elif methord == "get":
16                 res = requests.get(url,data)
17         return res
相關文章
相關標籤/搜索