【发布时间】:2020-06-23 07:43:05
【问题描述】:
我试图尝试在 BASH 脚本中发布请求,但不知何故,我的 json 数据无法在下面找到是我的代码。
header=$(curl -sb -H "Accept: application/json" "http://localhost:4040/api/tunnels")
# this is json format
tunnels=`echo "$header"`
echo "{'token':'xoxp-token-key','channel':'hybridteam','appname':'Server Unit', 'data': ${tunnels}}"
header2=$(curl -H "Content-type: application/json" -H "Accept: application/json" -sb -d "{'token':'token-key-here','channel':'hybridteam-ngrok','appname':'This is testing PC', 'data': ${tunnels}}" -X POST "https://localhost:8080")
success=`echo "$header2"`
echo $success
我的服务器获取这样的数据
$data = json_decode(isset($_POST['data'])? $_POST['data'] : $_GET['data']);
$token = isset($_POST['token'])? $_POST['token'] : $_GET['token'];
$channel = isset($_POST['channel'])? $_POST['channel'] : $_GET['channel'];
但在我的服务器上,我不断收到此响应
<br /> <b>Notice</b>: Undefined index: data in <b>C://xampp/htdocs/server/index.php</b> on line <b>30</b><br /> <br /> <b>Notice</b>: Undefined index: token in <b>C://xampp/htdocs/server/index.php</b> on line <b>31</b><br /> <br /> <b>Notice</b>: Undefined index: channel in <b>C://xampp/htdocs/server/index.php</b> on line <b>32</b><br />
请问我是 bash 脚本的新手,需要您的帮助。 谢谢。
【问题讨论】:
-
根据您的 PHP 实现,您期望 3 个单独的字段,并且您尝试只发送一个 json。