0

I try to use Postman to mock server functionality to mock an API call that will return status code 449. For some reason, the good response body is return, but the status code stays at 200.

I can change the example to return 404, 422, 451, and others, but as soon as I set 449 for the status code, it returns 200.

Is there a way to make the mock server return status code 449?

Edit: I add a collection and environment that reproduce the problems https://github.com/freddycoder/PostmanStatusCode

4

1 回答 1

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 %20 请求

以下站点显示了官方分配的状态代码。似乎到目前为止,邮递员不支持未分配的那些,期望 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;

要在 pre request set 中执行此操作:

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)
于 2020-11-22T01:42:38.707 回答