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);