Postman Mock Server 匹配请求体参数的算法逻辑 [英] Postman Mock Server matching algorithm logic for request body param

查看:42
本文介绍了Postman Mock Server 匹配请求体参数的算法逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下 API URL,我有两种方案.

I have two scenarios for the following API URL.

POST http://{{ip_port}}/oauth/token

POST http://{{ip_port}}/oauth/token

  1. 当我输入正确的用户名和密码时,它应该返回200 和模拟 json 响应.

  1. When I put the user name and password correctly, it should return 200 and mock json response.

当我输入的用户名和密码不正确时,它应该返回 401 并模拟 json(错误).

When I put user name and password incorrectly, it should return 401 and mocked json(error).

Postman Mock server 中,我注意到请求参数没有匹配的算法逻辑.

In Postman Mock server, I noticed that there is no matching algorithm logic for request param.

我想按请求参数过滤并返回相关的模拟响应.我不想为上述场景添加两个 URLs(/token and/failedtoken).

I want to filter by request param and return related mock responses. I don't want to add two URLs(/token and /failedtoken) for above scenarios.

目前Postman只支持三种匹配算法逻辑的逻辑.

Currently Postman only support three logic for matching algorithm logic.

  1. 格式正确的回复
  2. HTTP 方法
  3. 按网址过滤

Postman Mock Server 有没有什么办法可以让多个场景只添加一个网址?

Is there any way to add only one URL for many scenarios in Postman Mock Server?

推荐答案

Postman Mock Server 现在支持按请求正文进行匹配.您可以通过指定自定义标头(x-mock-match-request-bodytrue)来使用它.

Postman Mock Server now supports matching by request body. You can use it by specifying a custom header (x-mock-match-request-body to true).

您还可以通过转到 New->Templates 并搜索 Request Body Matching 来查看演示此功能如何工作的示例.

You can also check out an example that demonstrates how this feature works by going to New->Templates and searching for Request Body Matching.

这篇关于Postman Mock Server 匹配请求体参数的算法逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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