RT ,在用 postman 测试某个接口的时候,这个接口在请求头中会期待一个 uuid 的 header ,在请求体中会期待一个 req_id 的 field 。而这两个的值,理论上每次请求都应该是不同的。
不知道能不能够在 postman 里写 java 代码,让每次请求时自动调用这段代码,生成新的值置入这两个地方。
谢谢
不知道能不能够在 postman 里写 java 代码,让每次请求时自动调用这段代码,生成新的值置入这两个地方。
谢谢
|
1
postman 是支持脚本和环境变量的,不知道是不是你要的功能?
|
|
2
Pre-request Script 里可以设置变量,没试过 java, javascript 可以
|
|
3
Pre-request
|
|
xuelu520Sep 7, 2022
4
可以取 random+时间戳就行了。可以写 JS 的代码
|
|
5
Pre-request Script 设置变量 每次请求获取这个环境变量
|
|
6
pre-request script 里加段代码,生成 uuid ,目前好像都是 js 的代码,java 的不太清楚
function guid() { return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } UUID = guid() console.log("uuid ", UUID) //设置环境变量 postman.setEnvironmentVariable("uuid", UUID); 然后请求 param 或者其他地方直接使用{{uuid}}即可 |
|
silentskySep 7, 2022
7
用 apifox 吧 postman 卡 可以写前置脚本
|
|
silentskySep 7, 2022
9
apifox 可以写 java ,也可以将逻辑转换成 js 执行
|
|
cxxlxxSep 7, 2022
10
postman 可以 js 写脚本
|
|
11
|
|
wellermanSep 7, 2022
12
6 楼标准答案
|
|
brucmaoSep 7, 2022 via iPhone
13
用 jmeter 吧,可以写 Java ,可以写 Groovy
|
|
14
@Armor
@jpyl0423 @flashBee233 @codeMore @holystrike 谢谢各位的建议,我想问下,我设置了个随机数为请求头种的 uuid 的值,在请求发出后,出了后端的日志,在 postman 里该怎么看这个随机值是啥啊。。谢谢 |
|
codeMoreOct 22, 2022
15
在 pre-request script 加上打印就行了吧
console.log("要打印的内容") 然后点开 postman 下面的 console 框,里面就有具体的值 |