I'm just trying to send a POST
request with JS to server. But server has empty $_POST
array. I could use HTTP_RAW_POST_DATA
, but it'll be deprecated in PHP 5.6. Could I have posted data in my $_POST
array?
Environment: Chrome, apache2, PHP, AngularJS (I'm using $http.post
function).
Debug image (sorry for not attaching image directly - I have no 10 reputation)
The POST data must be in query string or multipart/form-data format to get decoded properly. Your data seems to be JSON, so you have to decode it by yourself:
$_POST = json_decode(file_get_contents('php://input'), true);
$_POST
is populated by a request that is of type form-urlencoded
or multipart/form-data
. Typically it looks like:
foo=bar&ipsum=lorm
So kinda like a GET
request.
Since you're posting JSON directly (which is awesome!) you can use:
$request_payload = file_get_contents("php://input");
See the docs for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With