json php input,在php中读取json输入
php://輸入在localhost中正常工作.但在服務(wù)器中它返回空.
輸入(請求)到我的站點是一個json(REST – 應(yīng)用程序/ 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://輸入可以幫助讀取該數(shù)據(jù).
我的代碼
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;
}
}
上面的代碼在另一個網(wǎng)絡(luò)服務(wù)器上工作正常,但不是在當前的. 🙁
我認為我的Web服務(wù)器拒絕訪問php:// input.
Is there is any other methods to read json input in php ?
總結(jié)
以上是生活随笔為你收集整理的json php input,在php中读取json输入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 朗逸多少钱一公里啊?
- 下一篇: 中卫做输卵管手术最好的医院推荐
