【问题标题】:Does postman mock server can return status code 449邮递员模拟服务器是否可以返回状态码 449
【发布时间】:2020-11-07 02:22:21
【问题描述】:

我尝试使用 Postman 模拟服务器功能来模拟将返回状态代码 449 的 API 调用。由于某种原因,良好的响应正文是返回,但状态代码保持在 200。

我可以将示例更改为返回 404、422、451 等,但是一旦我将状态码设置为 449,它就会返回 200。

有没有办法让模拟服务器返回状态码 449?

编辑: 我添加了一个重现问题的集合和环境 https://github.com/freddycoder/PostmanStatusCode

【问题讨论】:

    标签: server mocking postman http-status-codes postman-mocks


    【解决方案1】:

    449 不是官方状态码。

    https://dynomapper.com/blog/254-the-6-types-of-http-status-codes-explained#:~:text=A%20449%20error%20appears%20when,order%20to%20fulfill%20a%20request.

    以下网站显示了官方分配的状态代码。到目前为止,postman 似乎不支持未分配的那些,期望 apache 状态代码 509。也许模拟服务器使用 apache,449、450 等是 Windows 特定的状态代码。

    https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

    您可以使用 x-mock-response-code 请求标头

    测试特定用例

    在设置此标头时,邮递员仅在模拟服务器示例的状态码设置为 449 时才返回响应。

    否则你会得到 404 mockRequestNotFoundError 。

    所以在您的测试中,如果响应代码为 200,您可以设置 pm.response.code = 449;

    在预请求集中执行此操作:

    pm.response.code===200?pm.response.code=449:null
    pm.response.code===449?pm.response.status="Retry With":null
    
    console.log(pm.response.code,pm.response.status)
    

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多