php curl 发送jso数据代码如下:
class curl_data{
public function send_data($url,$data){
$httpheader = array('Content-type: application/json','Content-length:'.strlen($data)); #设置头
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_HTTPHEADER,$httpheader);
$rs = curl_exec($ch);
echo $rs;
curl_close($ch);
}
}
接收json数据使用:$GLOBALS['HTTP_RAW_POST_DATA'];