萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php使用curl發送json格式數據實例

php使用curl發送json格式數據實例

 這篇文章主要介紹了php使用curl發送json格式數據的實例,大家參考使用吧

 代碼如下: $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);    
copyright © 萬盛學電腦網 all rights reserved