【问题标题】:How to retrieve the HTTP code using postman from a Json slim response?如何使用邮递员从 Json slim 响应中检索 HTTP 代码?
【发布时间】:2019-03-27 14:05:56
【问题描述】:

我目前正在使用 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 错误请求
内容类型:application/json;
字符集=utf-8

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

你对这种邮递员的行为有任何想法吗?

【问题讨论】:

    标签: php json postman slim postman-collection-runner


    【解决方案1】:

    与 slim github 存储库中的 this issue 相关,您必须返回响应,而不是回显它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 2023-04-05
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多