Get POST data in PHP
So I'm running this to retrieve my POST data:
$jsonString = file_get_contents('php://input');
If I go to print out the $jsonString
, I get the results like so:
开发者_运维知识库Something=Value&OtherThing=Value&Etc=Yougetmydrift
Now in the past I've been able to do this:
$object = json_decode($jsonString);
$something = $object->Something;
echo $something; // would print 'Value'
But I'm currently experiencing this not working. I'm working with the Android SDK and php://input
on the back end seems to be returning nothing. Does anyone know why this is?
I think you just want:
echo $_POST["Something"];
You shouldn't need to do file_get_contents('php://input');
. PHP automatically fills the variable $_POST
with post data.
echo $_POST['Something']; // Value
Also, just FYI: Something=Value&OtherThing=Value&Etc=Yougetmydrift
isn't JSON, it's a query string. If you really wanted to parse it, you should use parse_str($string, $result)
docs.
the file_get_contents('php://input');
style is usually used for PUT data. For POST PHP provides a built in super-global array called $_POST.
use: urldecode
/ urlencode
, not json_decode
精彩评论