shell端:
#!/bin/bash
#通用变量
TIME_INTERVAL=5
time=$(date “+%Y-%m-%d %H:%M:%S”)
url=http://xxx/GetPost.php
//
数据操作
//
post方式发送
curl -i -X POST -H "'Content-type':'application/json'" -d '{"memused":"'${mem_used}'","memtotal":"'${mem_total}'","nip":"'${nip}'","wip":"'${wip}'","daxiao":"'${daxiao}'","CPU":"'${CPU}'","ioin":"'${ioin}'","ioout":"'${ioout}'"}' ${url}
发送的数据一定要使用"’${mem_used}’"方式包起来,不然PHP端接收到的json数据,进行json_decode()处理后,会出现多一个_的事情,导致获取的数据为null
GetPost.php
<?php
echo "连接成功";
if (!$_POST) {
var_dump( 'not have data');
} else {
$json_arr = (array_keys($_POST));
$json_e =($json_arr[0]);
$json = str_replace("_",".",$json_e);
$arr=(json_decode($json, true));
var_dump($arr);
}
?>