有没有办法让邮递员从 GET 请求中读取响应数据,然后使用 IF THEN 语句来 运行 一个 POST 请求?
Is there a way for postman to read the response data from a GET request and then use an IF THEN statement to run a POST request?
我正在尝试 运行 邮递员发送 Get 请求的脚本,如果 get 响应包含某个变量,则 运行 一个 Post 请求。我该怎么做?
(也有办法 运行 每小时获取一个请求)
在先决条件中添加:
// set initial value
const method = pm.variables.get("method")
// set initial value as GET if method is undefined
method ? null : pm.variables.set("method", "GET")
// Set this as method
pm.request.method =method
在测试脚本中添加:
// the condition check
if (pm.response.json().somevalue === "somevalue") {
//then change the method
pm.variables.set("method", "POST")
//call the same request again using setNExtRequest
// pm.info.reqeustName gives current request's name
postman.setNextRequest(pm.info.requestName)
}
我正在尝试 运行 邮递员发送 Get 请求的脚本,如果 get 响应包含某个变量,则 运行 一个 Post 请求。我该怎么做?
(也有办法 运行 每小时获取一个请求)
在先决条件中添加:
// set initial value
const method = pm.variables.get("method")
// set initial value as GET if method is undefined
method ? null : pm.variables.set("method", "GET")
// Set this as method
pm.request.method =method
在测试脚本中添加:
// the condition check
if (pm.response.json().somevalue === "somevalue") {
//then change the method
pm.variables.set("method", "POST")
//call the same request again using setNExtRequest
// pm.info.reqeustName gives current request's name
postman.setNextRequest(pm.info.requestName)
}