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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -