php - Send json as request body or POST json in a variable -
i trying figure out, there way of sending raw json php instead of post parameter. if possible way best mean either request body or post parameter.
send http request has json string request body (here: using curl
on command line):
$ curl -d '{"foo":"bar"}' example.com/test.php
read request body in php:
$json = file_get_contents('php://input');
decode it:
$data = json_decode($json, true);
php's $_post
superglobal automatically populated array if request body of post request contains url encoded key-value pairs (e.g. foo=bar&baz=42
). in above example you're still using http post request "post data". doesn't automatically end in $_post
because php doesn't know how decode json automagically.
Comments
Post a Comment