2017-07-17 156 views
0

我試圖發送HTTP POST JSON的身體,不知道如何與纖薄處理我試圖找到計算器不同勢soluctions但它顯示錯誤500 我tryed
$app->post('/login', function() use ($app) { $json = $app->request->getBody(); $data = json_decode($json, true); });
但它返回「修身應用程序錯誤 發生網站錯誤,對於暫時​​的不便,我們深表歉意。「如何在Slim rest api中訪問POST請求的JSON請求正文?

+0

500,有一些你的苗條身材。有'/ login'作爲post?,或者get ?,存在嗎?... –

+0

我不在stand下sir –

回答

1

您只需要從修身得到解析請求主體
修身照顧解碼,併發送回給你的PHP數組您還將添加請求和響應在您的路由功能
你的代碼會是這樣的

$app->post('/login', function ($request,$response){ 
    $Arr = $request->getParsedBody(); 
    //you did not need to re decode the body using this way  
    //$data = json_decode($json, true); 
}); 
+0

$ app-> post('/ login',function($ request,$ response,$ args ){ \t $ data = $ request-> getParsedBody(); \t \t}); –

+0

問題看起來像苗條v2,但你的答案顯示從v3代碼 – jmattheis