邮递员模拟服务器能否返回状态码449

时间:2020-11-07 02:22:21

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

我尝试使用Postman来模拟服务器功能来模拟将返回状态码449的API调用。由于某种原因,返回的响应主体良好,但是状态码仍为200。

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

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

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

1 个答案:

答案 0 :(得分:0)

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

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

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

您可以使用 x-mock-response-code 请求标头测试特定的用例

enter image description here

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

enter image description here

否则,您将收到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)