Slim 3 post方法返回空

时间:2016-10-27 19:05:00

标签: php post zend-framework http-post slim

当我向此网址提交操作时,还会通过邮递员测试此API。它不打印POST数据。

但是get方法正在运行。

$app = new \Slim\App;

$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();

$app->add(new \Slim\Middleware\JwtAuthentication([
    //"secure"      => false,
    //"relaxed"         => ["localhost", "api.f2f.dev"],
    "header"        => "X-Token",
    "path"          => ["/v2"],
    "passthrough"   => ["/v1/api/token/", "/test", "/v1"],
    "secret"        => getenv("TOKEN_SECRET")
]));

$app->post("/v1/app/register", function ($request, $response, $arguments) {
     return $allPostPutVars = $request->getParsedBody();
});

我找不到这个问题。但未解析的数据能够打印。

欢迎任何帮助。 Slim 3上的任何帖子方法也受到欢迎。

谢谢。

1 个答案:

答案 0 :(得分:2)

您的回调应该返回实现Psr\Http\Message\ResponseInterface的响应对象。它没有。所以,作为一个例子:

$app->post("/v1/app/register", function ($request, $response, $arguments) {
    $params = $request->getParams();
    return $response->getBody()->write('You have posted '.count($params).' parameters.');
});

有时你需要快速而肮脏的检查。然后,您可以执行以下操作:

$app->post("/v1/app/register", function ($request, $response, $arguments) {
    $params = $request->getParams();
    print_r($params);
    die();
});
相关问题