I have sent JSON
data using android java by setting it in the post entity like this:
HttpPost httpPostRequest = new HttpPost(URLs.AddRecipe);
StringEntity se = new StringEntity(jsonObject.toString());
httpPostRequest.setEntity(se);
How can I receive this json
data in the php
, where I am using Slim framework
?
I have tried this:
$app->post('/recipe/insert/', 'authenticate', function() use ($app) {
$response = array();
$json = $app->request()->post();
});
You need to get the response body. Save it in a variable. After that, verify if the variable is null and then decode your JSON.
JSON is not parsed into
$_POST
superglobal. In$_POST
you can find form data. JSON you can find in request body instead. Something like following should work.