jmeter传参二:get与post请求参数传递方法

得到开发提供的接口文档后,就可以开始写脚本了,如:

1. get请求的入参是json格式的

摘要:

利用httpClient调用接口,成功返回信息

接口地址:
(RESTFUL方式)

http://192.168.100.87:10051/ngcctcontrol/ws/interfaces/userSatisfy

请求方式:

GET

步骤:

1利用httpClient模拟接口调用正常情况

输入报文:

{
    "params":{
        "beginTime":"2017-01-01 00:00:00",

"endTime":"2017-01-25 00:00:00",

"userSatisfy":"1",

"userSatisfy2":"1",

"serviceTypeId":"otck"
    },

"object":[],

"beans":[]
}

 

{\"params\":{\"beginTime\":\"2017-01-01 00:00:00\",\"endTime\":\"2017-01-25 00:00:00\",\"userSatisfy\":\"1\",\"userSatisfy2\":\"1\",\"serviceTypeId\":\"otck\"},\"object\":[],\"beans\":[]}

beginTime,endTime,不大于30serviceTypeId//

要用URLencode转码,参见另一篇文章《jmeter json入参转化为get的入参


2. get请求是普通的键值对

摘要:

利用httpClient调用接口,成功返回异常信息

 

输入参数:

var param = {
                    "billId":"13312212121",
                    "log":"haha"
                }

接口地址:
(RESTFUL方式)

http://192.168.100.36:8843/ngbusi_gx/front/sh/custInfo!execute?uid=queryVpmnGrpInfoDetail

请求方式:

GET


这个很简单,只要用&链接符把他们一个个都放到URL里面就可以了,如下(截图是POST请求点错了,应该是get)



3,json格式的post请求

摘要:

利用httpClient调用接口,成功返回信息

接口地址:
(RESTFUL方式)

http://192.168.100.87:10051/ngcctcontrol/ws/interfaces/contactsingleope

请求方式:

POST

步骤:

1利用httpClient模拟接口调用正常情况

输入报文:

{
    "params":{
        "serialNo":"201701231140480000000000154926",
        "contactId":"201701231140480000000000154926",

"channelId":"08000701",

"channelName":"4G管家",

"mediaTypeId":"01",

"mediaTypeName":"webChat",

"callType":"0",

"provinceId":"00030001",

"ctiId":" 1",

"ccid":" 1",

"vdnId":" 1",

"callId":"14640099272192501",

"callIdTime":"1464009927",

"callIdDsn":"21925",

"callIdHandle":"0",

"callIdServer":" 1",

"callSkillId":" 1",

"callerNo":"psx34_163.com",

"calledNo":"5323738",

"subsNumber":"13837829820",

"orgCallerNo":"",

"orgCalledNo":"045110086",

"staffId":"HA10031",

"remark":"",

"contactStartTime":"2017-01-23 11:40:48",

"contactEndTime":"2017-01-23 16:35:55",

"playRecordFlag":"0",

"qcFlag":"0",

"qcStaffId":" HA 10001",

"staffHangup":" 1",

"surveyTypeId":" 01",

"userSatisfy":" 1",

"userSatisfy2":" 1",

"userSatisfy3":" 1",

"hasRecordFile":" 1",

"custId":"",

"custName":"",

"custLevelId":"",

"custLevelName":"",

"custBrandId":"",

"custBrandName":"",

"custCityId":" 000300010011 ",

"custCityName":"昌平",

"custCityId2":" 000300010012 ",

"custCityName2":"大兴",

"firstResponseTime":"2017-01-23 11:40:48",

"fstCharAttrVal":"",

"secdCharAttrVal":"",

"thrdCharAttrVal":"",

"fothCharAttrVal":"",

"fithCharAttrVal":"",

"sxthCharAttrVal":"",

"svthCharAttrVal":"",

"egthCharAttrVal":"",

"nithCharAttrVal":"",

"tenCharAttrVal":"",

"elevCharAttrVal":"",

"twlfCharAttrVal":"",

"thtnCharAttrVal":"",

"fotnCharAttrVal":"",

"fitnCharAttrVal":"",

"sitnCharAttrVal":"",

"svtnCharAttrVal":"",

"eitnCharAttrVal":"",

"nitnCharAttrVal":"",

"twthCharAttrVal":"",

"toUserId":"sinaweibo2001627641",

"toUserName":"中国移动",

"fromOrgId":"",

"releaseReason":"",

"staffCityId":"99100000",

"staffProvinceId":"00030050",

"startRingTime":"",

"serviceTypeId":"otck",

"ctiCallId":"",

"callTrace":"",

"digitCode":"",

"srFlag":"",

"languageId":"",

"languageName":"",

"callSkillName":"4G管家,集中坐席",

"workNo":""
    },

"object":[],

"beans":[]
}


这个很简单,只要把入参放到BodyData里面就可以了,记得要先用json在线校验工具进行校验,另外要加http头管理器,在里面加上content-type:Application/json




响应结果:

由于json字符串在Body Data中传递,故请求的数据都在Post Data中,而post只有路径



4.post请求的键值对

除了放到BodyData里,有时候放到URL里,用&连接符,类似情况2的get请求。如下图的登录场景,传递用户名和密码



可以看到参数是在POST中而非POST DATA



5.parameters选项卡中填写而非bodydata,但与bodaydata效果一样

注意:

a.    name是空,没有填写,仅写了value,亦可传送

b.    在Parameters中填写表格形式的入参,信息头管理器可以没有,但不可写成“Content-Type: application/json”否则报错



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值