首页 > 代码库 > 接口测试之混合参数发送
接口测试之混合参数发送
“混合参数”指的是Post请求参数中既有普通字符串参数,又有json格式的参数。如添加房源时post的参数:
首先我们需要登录系统才能够获取它的session,获取session后可以直接对单个接口进行测试。下面代码是测试“保存”房源接口:
#coding=utf-8 import requests import json data1 = { ‘Account‘:"System", ‘Password‘:"4a7d1ed414474e4033ac29ccb8653d9b" } s = requests.session() s.post(url=‘http://10.10.134.86:8083/Login/CheckLogin‘,data=http://www.mamicode.com/data1) r=s.get(‘http://10.10.134.86:8083/Home/AccordionIndex‘) print(r.text) house={"XnewHouseCode":"","ErpHouseCode":"11302498","ErpHouseAddress":"318国道1881号222fsf路十弄22号楼1号房","ErpCode" :"131798","ErpDistrictName":"318国道1881号","Room":"2","Hall":"1","Thebalcony":"1","Area":"123","SumFloor" :"20","PlaceFloor":"1","HousekeeperNo":"","HousekeeperName":"","CustomserviceNo":"","CustomserviceName" :"","BrokerNo":"16ACCDAE-FF34-43AA-8FC4-991B898F2FF5","BrokerName":"李鸿坤","LendType":"1","AddName":"" ,"AddDate":"","EntrustMoney":0,"MonthMoney":0,"SeasonMoney":0,"HalfyearMoney":0,"YearsMoney":0,"Orientation" :None,"RecommendType":None,"HouseTitle":None,"Description":"","DecorationStyleCode":None,"DecorationStyleName" :None,"AreaCode":None,"BusinessAreaCode":None,"ModifyPerson":"","ModifyDate":None,"Characteristic":"" ,"RoomInfo":[],"HouseImage":[],"RoomImage":[]} data2={ ‘KeyValue‘:None, ‘houseJson‘:json.dumps(house), ‘houseassetallocationJson‘:‘[]‘, ‘roomsJson‘:‘[]‘ } r=s.post(url=‘http://10.10.134.86:8083/HouseModule/HouseInfo/Insert‘,data=http://www.mamicode.com/data2) print(r.text)
上面代码先将houseJson参数值进行编码,然后再Post
接口测试之混合参数发送
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。