I have this problem.
I used this sentence to get post info in CodeIgniter 1.7.2 and it works fine
function function1(){
$input_data = json_decode(trim(file_get_contents('php://input')), true);
$info = str_replace( '"', '', json_encode($input_data['info']));
}
My input json is this:
{
"info":"hello!"
}
But when I used these same lines in CodeIgniter 2.1.3 it doesn't work. I used echo $info
but my answer is null
. Anyone can help me? Where is the mistake?
This behavior is not CI related. It's most PHP concepts. Your mistake is probably that you're trying to access something that doesn't exist.
What is the point to use file_get_contents('php://input')
? Can't you just use $this->input->post()
, or the upload
class? (in CI context)?
Anyway, check what do you get in file_get_contents()
, var_dump
ing it. I'm pretty sure that your NULL
comes from $input_data
assignment statment, so you're fetching the JSON in the wrong way at first.
I'm using a Controller as a WebService and It works fine in a previous work. So, I tested with this
function test(){
$m = $this->input->post('key');
echo $m;
}
and I'm sending a POST JSON data as follow:
{
'key':'hello!"'
}
and now I receive nothing. Some else?