api - 邮递员有没有办法从 GET 请求中读取响应数据,然后使用 IF THEN 语句来运行 POST 请求?
问题描述
我正在尝试运行邮递员发送 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)
}
推荐阅读
- tensorflow - TensorFlow:类别的数量是否有限制,是否可以扩展?
- javascript - 从 React 应用程序向 Rocket 后端发送 POST 请求时出错
- angular - Angular 6:找不到名称'bootbox'
- php - 如何计算列中相同结果的数量?
- java - 为什么我在 servlet 中使用“sendReeditect”时得到空值,如下所示
- testing - Clojure - 如何在实现中检测另一个协议
- angular - 将变量分配为数组中的键
- php - 使用 php 查找数组的第一个元素并将其添加到活动类以使用 bootstrap.js 创建选项卡系统
- ruby - 从数组中创建散列,其中值是元素的索引
- android - Kotlin Activity 将书写顺序从左到右更改为从右到左(带有不同语言的电话)