how PHP uses curl to send JSON-formatted data instances
How PHP uses Curl to send JSON-formatted data instances
This article mainly introduces PHP using Curl to send JSON format data instances, we refer to the use of code as follows:
$urlcon = ' http://localhost/******.php ';
$data = ' {
"Button": [
{
"Type": "Click",
"Name": "Song of the Day",
"Key": "V1001_today_music"
},
{
"Type": "Click",
"Name": "Introduction to the singer",
"Key": "V1001_today_singer"
},
{
"Name": "Menu",
"Sub_button": [
{
"Type": "Click",
"Name": "Hello word",
"Key": "V1001_hello_world"
},
{
"Type": "Click",
"Name": "Praise Us",
"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);