当前位置:Gxlcms > PHP教程 > 怎么使用post提交json数据

怎么使用post提交json数据

时间:2021-07-01 10:21:17 帮助过:3人阅读

如何使用post提交json数据
如何使用php的post提交json数据...
------解决方案--------------------
以下是一个例子,你可以按需扩展。
$post_data =   
array(
'name'=>'aaa',
'age'=>45,
);


$url='http://www.example.com/example.php';

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
echo $result;

人气教程排行