Why am I unable to access the json data POST'd to my codeigniter application? Why am I unable to access the json data POST'd to my codeigniter application? curl curl

Why am I unable to access the json data POST'd to my codeigniter application?


Your post data is not in query string format so you should skip dealing with $_POST and go straight to the raw post data.

try

var_dump($HTTP_RAW_POST_DATA);

or even better

var_dump(file_get_contents("php://input")); 


in codeigniter 2.X, you can override Input class and add necessary functionality.https://ellislab.com/codeigniter/user-guide/general/core_classes.html

  1. add file MY_Input.php to application/core
  2. add code inside this file:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');class MY_Input extends CI_Input {    public function raw_post() {        return file_get_contents('php://input');    }    public function post($index = NULL, $xss_clean = FALSE) {        $content_type = $this->get_request_header('Content-type');        if (stripos($content_type, 'application/json') !== FALSE            && ($postdata = $this->raw_post())            && in_array($postdata[0], array('{', '['))) {            $decoded_postdata = json_decode($postdata, true);            if ((json_last_error() == JSON_ERROR_NONE))                $_POST = $decoded_postdata;        }        return parent::post($index, $xss_clean);    }}