首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >postman有没有办法从GET请求中读取响应数据,然后使用IF then语句来运行POST请求?

postman有没有办法从GET请求中读取响应数据,然后使用IF then语句来运行POST请求?
EN

Stack Overflow用户
提问于 2021-09-29 00:58:26
回答 1查看 46关注 0票数 -1

我正在尝试运行一个脚本,postman在该脚本中发送Get请求,如果get响应包含某个变量,则运行Post请求。我该怎么做呢?

(还有没有办法每小时运行一次get请求)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-29 08:47:44

在先决条件添加中:

代码语言:javascript
运行
复制
// 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

在测试脚本中添加:

代码语言:javascript
运行
复制
// 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)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69369917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档