curl传递json数据

$ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json; charset=utf-8',
    'Content-Length: '.strlen($data))
);
$result = curl_exec($ch);
curl_close($ch);//关闭

服务端接收的函数
$GLOBALS["HTTP_RAW_POST_DATA"];
json_decode()
转换成数组

你可能感兴趣的:(php)