2016-05-28 5 views
0

Slim v3を使用しています。作曲家経由でインストールされます。私は私がのRuntimeExceptionエラーCould not write to streamを取得する郵便配達を経由して{"name":"jack", "age":"10", "gender":"male"} のようなサンプルJSONを投稿するSlim v3を使用してJSON POSTデータを取得する

use \Psr\Http\Message\ServerRequestInterface as Request; 
use \Psr\Http\Message\ResponseInterface as 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(); 

: はここに私のregister.phpファイルです。 私は既に$app->request()->post();$request->getParams();$request->getParsedBody();を使用していますが、未定義の方法などの他のエラーに直面しています。 私を助けてください。

答えて

1

私は、あなたが要求しませgetParamsgetBody()を使用することになっていると思う:

$json =$request->getBody(); 
+0

感謝を使用することができます。問題は依然として存在する。私は$ argsのためだと思う。 本当にそれが必要ですか?または使用する($ app)@iturki –

+0

@ mehrdad-pedramfar私はそうは思わない。スリム3または2を使用していますか? – iTurki

+0

バージョン3.私はそれを描き出す!問題は$ argsでした。 –

1

あなたはあなたの答えのために

 
//-------------- Register ------------------ 
$app->post('/', function (Request $request, Response $response, $args) use ($app) { 
    $json =$request->getParams(); 
    return $response->withJson($json); 
}); 
関連する問題