欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php使用curl发送json格式数据实例

程序员文章站 2022-03-12 18:43:42
复制代码 代码如下:$urlcon= 'http://localhost/******.php';$data=' {"button":[{ "type":"click","...

复制代码 代码如下:

$urlcon= 'http://localhost/******.php';
$data=' {
"button":[
{
"type":"click",
"name":"今日歌曲",
"key":"v1001_today_music"
},
{
"type":"click",
"name":"歌手简介",
"key":"v1001_today_singer"
},
{
"name":"菜单",
"sub_button":[
{
"type":"click",
"name":"hello word",
"key":"v1001_hello_world"
},
{
"type":"click",
"name":"赞一下我们",
"key":"v1001_good"
}]
}]
}';

$host = $urlcon;
$ch = curl_init();
$data = 'data='.$data;
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_url,$host);
curl_setopt($ch,curlopt_returntransfer,1);
curl_setopt($ch, curlopt_postfields, $data);
echo $output = curl_exec($ch);
curl_close($ch);