【问题标题】:Postman does not accept `-` as an URI param for mocking server requestsPostman 不接受 `-` 作为模拟服务器请求的 URI 参数
【发布时间】:2020-05-02 05:22:26
【问题描述】:

我收到以下错误响应:

{
    "error": {
        "name": "mockRequestNotFoundError",
        "header": "No matching requests",
        "message": "Double check your method and the request path and try again."
    }
}

当我将- 作为通过模拟服务器创建的 Postman 请求的 URI 参数传递时,与我在不是通过模拟服务器创建的请求中传递相同的 URI 参数值不同,它运行良好!

网址:http://{{host}}/order/{{subUserId}}/{{BusinessDate}}/5

主持人:{mocking-server-url-without-http-keyword}

subUserId:1

营业日期:2020-01-12-17-07-21

HTTP 请求头:x-api-key{{postman_secret_API_key}}

以mocking server作为主机正确返回数据的主请求:

以mock服务器为主机的mock请求返回错误:

【问题讨论】:

  • 你能用完整的 URI 更新问题吗?您在示例或请求中是否使用了其他标头?

标签: unit-testing request mocking postman


【解决方案1】:

模拟 example 需要匹配主请求的路径才能返回。

例如:

如果没有,它将无法找到您正在使用的模拟 example

我不确定您的特定上下文,但您也可以在主要请求中使用不同的 Request Headers 来指向特定的模拟示例:

x-mock-response-code:200
x-mock-response-name:<name of the mock example>

【讨论】:

  • 我对主请求和模拟响应使用相同的路径,而在 URI 中传递这个字符 - 时出现问题,因为当我用 / 替换它时,我成功地重新调整了模拟数据所以这可能是Postman 中的一个错误。
  • 我在提出的请求中使用该字符没有问题,因此它们可能也是您正在做的其他事情。如果没有有关完整请求的更多详细信息,将很难提供帮助。如果您想在 Postman 社区论坛上提出问题,我可以为您提供更多帮助。 community.getpostman.com
  • 您是否在测试用例中将 Postman API 密钥作为 HTTP 标头 X-Api-Key 发送? learning.getpostman.com/docs/postman/postman-api/intro-api
  • 如果模拟是私有的(您必须在创建服务器时选择该选项),那么您需要使用 x-api-key 标头。
  • 我在community.getpostman.com community.getpostman.com/t/…创建了一个主题
猜你喜欢
  • 2017-12-16
  • 2019-11-04
  • 2017-07-14
  • 1970-01-01
  • 2021-05-14
  • 2018-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多