php - Cant get JSON POST data using Slim v3 -
im using slim v3 . installed via composer. here register.php file :
use \psr\http\message\serverrequestinterface request; use \psr\http\message\responseinterface response; require 'vendor/autoload.php'; $app = new \slim\app(['settings' => ['displayerrordetails' => true]]); //-------------- register ------------------ $app->post('/', function (request $request, response $response ,$args) use($app) { $json =$request->getparams(); $data = json_decode($json, true); $response->getbody()->write($data); return $response; }); $app->run();
when post sample json like{"name":"jack", "age":"10", "gender":"male"}
via postman runtimeexception error could not write stream
. use $app->request()->post();
, $request->getparams();
, $request->getparsedbody();
face other errors undefined method , on . please me.
i think supposed use getbody()
request, not getparams
:
$json =$request->getbody();
Comments
Post a Comment