get 方法用例
url = "https://aip.douban.com/"#首页地址 url_path =url + "v2/book/search"#子页地址 data ={"q":"bb"}#需要传入的数据 re = requests.get(url = url_path,params = data)#获取地址,传入数据 json_1 =re.json()#转换json格式 asser_Equal(re.status_code,200,"接口请求失败")
post方法用例
url = "https://manage-eloan-test.xinzhentech.com/modules/ecust/ecustInfo/saveOrUpdate.htm" datas = {"contacts":[{"contactuser":"深圳","contactphone":"13245937882"}]} header = {'Accept':'text/javascript, text/html, application/xml, text/xml, */*', 'Accept-Encoding':'gzip, deflate', 'Accept-Language':'zh-CN,zh;q=0.8', 'Connection':'keep-alive', 'Content-Length':'203', 'Content-Type':'application/x-www-form-urlencoded', 'Cookie':'JSESSIONID=6C572BAB9C882B07B2A51B162668D403; username=system', 'Host':'manage-eloan-test.xinzhentech.com', 'Origin':'https://manage-eloan-test.xinzhentech.com', 'Referer':'https://manage-eloan-test.xinzhentech.com/build/index.html;
jsessionid=D7EB59F8AFCEF0046BF6C6B962CEAD66', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36
(KHTML,likeGecko) Chrome/49.0.2623.110 Safari/537.36', 'X-Requested-With':'XMLHttpRequest', } ret = request.post(url,data = datas ,headers = header) r_dict = ret.json() assert_Equal(r_dict["msg"],"对比结果","自定义报错提示信息") assert_Equal(r_dict[code],200,"自定义报错信息")