【发布时间】:2019-08-07 21:41:28
【问题描述】:
我正在使用Slim v4 来获取一些 arduino 组件 API。当我通过控制器调用 POST 时,我得到一个空的请求正文,没有我发送给它的参数。
在下面的代码中,$parameters 变量中我有一个 NULL。
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response
) : ResponseInterface {
$ret = [
'success' => false
];
$parameters = (array) $request->getParsedBody();
}
我正在使用 postman 执行 CURL 请求,但当我在 bash 中使用 curl 时也会出现此错误。
下面的代码是我注册新 API 调用的方式。
$application = AppFactory::create();
$application->group('/ambient', function(RouteCollectorProxy $routeCollector) {
$routeCollector
->post('/register', RegisterAmbientController::class)
->setName('register-ambient');
});
你也可以在我的github上看到完整的代码: https://github.com/JasterTDC/ardu-component/tree/feature/register-temp-humidity
提前致谢!
【问题讨论】: