我目前正在使用Slim框架开发REST API。 要测试我的API,我正在使用postman但我无法检索slim方法发送的状态代码:
$response->withJson($data, $status, $encodingOptions)
$slimApp->post('/v1/users', function(Request $request, Response $response) {
echo $response->withJson(['data' => 'something'], 400);
});
我将状态代码设置为'400',但邮递员一直说它是'200'状态。
瘦身发送的标题是:
HTTP / 1.1 400错误请求 Content-Type:application / json; 字符集= utf-8的
事实是,我可以用标题手动验证代码状态,但我想通过postman的集合运行器验证它。
你对这个邮递员的行为有什么想法吗?
关于精简github存储库中的this issue,您必须返回响应,而不是回显它:
$slimApp->post('/v1/users', function(Request $request, Response $response) {
return $response->withJson(['data' => 'something'], 400);
});