如何使用 postman 从 Json slim 响应中检索 HTTP 代码?

How to retrieve the HTTP code using postman from a Json slim response?

我目前正在使用 Slim 框架开发 REST API。
为了测试我的 API 我正在使用邮递员,但我无法检索通过 slim 方法发送的状态代码:

$response->withJson($data, $status, $encodingOptions)

$slimApp->post('/v1/users', function(Request $request, Response $response) {
    echo $response->withJson(['data' => 'something'], 400);
});

我将状态代码设置为“400”,但邮递员一直说这是“200”状态。

slim 发送的 header 是:

HTTP/1.1 400 Bad Request
Content-Type: application/json;
charset=utf-8

事实是,我可以用header手动验证代码状态,但我想通过postman的collection runner来验证它。

你知道这个邮递员的行为吗?

关于 slim github 存储库中的 this issue,您必须 return 响应,而不是回应它:

$slimApp->post('/v1/users', function(Request $request, Response $response) {
    return $response->withJson(['data' => 'something'], 400);
});