接口测试之混合参数发送

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接口测试之混合参数发送相关的知识,希望对你有一定的参考价值。

“混合参数”指的是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=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=data2)
print(r.text)

上面代码先将houseJson参数值进行编码,然后再Post

 

以上是关于接口测试之混合参数发送的主要内容,如果未能解决你的问题,请参考以下文章

将接口从片段传递到kotlin中的活动

Python接口自动化测试之详解post请求

python接口测试之requests库

python接口自动化测试三:代码发送HTTP请求

Postman Postman测试接口之POST提交本地文件数据

接口测试之PostmanJmeter的使用