使用Postman获得下一个迭代 [英] Using Postman to get next iteration

查看:266
本文介绍了使用Postman获得下一个迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Postman从Web服务获取结果。

I'm using Postman to get results from a web service.

Web服务将结果分成50个块,上一个请求URL在上一个JSON返回如下:

The web service splits the results into chunks of 50, with the next request URL within the previous JSON return like this:

{
    "type": "user.list",
    "pages": {
        "type": "pages",
        "next": "https://api.webservice.io/users?per_page=50&page=2",
        "page": 1,
        "per_page": 50,
        "total_pages": 2721
    },
...

有没有一种方法可以自动请求下一页,直到获得所有结果?

Is there a way I can automatically request the next page until I have all the results?

推荐答案

是。

您可以解析响应中的 next 并设置 postman.setNextRequest('< next url>')旁边的值。

You can parse the next in your response and set the value of next to postman.setNextRequest('<next url>').

例如-在测试中部分添加此代码

Eg - In your tests section add this code

try {
  var userList = JSON.parse(responseBody);

  // Do whatever you have to do with the response 
  // Check if userList.pages.next is valid string 
  // If valid do

  postman.setNextRequest(userList.pages.next);

} catch (e) {
  console.log('Error parsing JSON', e);
  postman.setNextRequest(null);
}

参考-邮递员中的有条件工作流

这篇关于使用Postman获得下一个迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆