PHP curl传输json数据及接收

……

//开启header
curl_setopt($curl, CURLOPT_HEADER, true);
//类型为json
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json; charset=utf-8'
)
);

//post传递
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, ($json));
……

……

//接收 $json = file_get_contents("php://input"); $json = json_decode($json, true); print_r($json); ……

 

posted @ 2017-04-14 15:55  码一个大馒头  阅读(10432)  评论(0编辑  收藏  举报