php://输入在localhost中正常工作.但在服务器中它返回空.
输入(请求)到我的站点是一个json(REST – 应用程序/ json类型),所以$_POST不起作用(请阅读
This question).
$_POST works with key-value pair type inputs like form-data or x-www-urlencoded
key1=value1&key2=value2&key3=value3
我正在使用application / json作为输入(在REST中).
Like {‘key1′:’value1′,’key2′:’value2′,’key3′:’value3’}
使用$_POST无法处理此问题.但是使用php://输入可以帮助读取该数据.
我的代码
class Webservice_Controller extends CI_Controller {
public $json_input_data;
public function __construct(){
parent::__construct();
$this->json_input_data = json_decode(file_get_contents('php://input'),TRUE);
}
public function json_input($label){
if(isset($this->json_input_data[$label])) return $this->json_input_data[$label];
else return NULL;
}
}
上面的代码在另一个网络服务器上工作正常,但不是在当前的. 🙁
我认为我的Web服务器拒绝访问php:// input.
Is there is any other methods to read json input in php ?