如何在Slim rest api中访问POST请求的JSON请求正文?
我试图发送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请求正文?
您只需要从修身得到解析请求主体
修身照顾解码,并发送回给你的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);
});
$ app-> post('/ login',function($ request,$ response,$ args ){ \t $ data = $ request-> getParsedBody(); \t \t}); –
问题看起来像苗条v2,但你的答案显示从v3代码 – jmattheis
500,有一些你的苗条身材。有'/ login'作为post?,或者get ?,存在吗?... –
我不在stand下sir –