dpizd08264 2013-11-25 04:53
浏览 37

无法在php中的_POST变量中获取JSON数据

I'm using this curl command to send json data to a php webservice, but i'm not getting anything in the $_POST variable.

Here is the curl command

 curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST http://192.168.2.127:8888/json.php -d '{"age":"234","password":"password"}'

and here is the php code.

<?php
header('Content-type: application/json');

var_dump($_POST);
$return_arr = array();
$age = $_POST['age'];
$ageInt = intval($_POST['age']);
$return_arr['age1'] = $age;
var_dump($_POST);
$return_arr['age2'] = $ageInt;
echo json_encode($return_arr);
?> 

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dsfs5420 2013-11-25 05:42
    关注

    Once try this

    curl -X POST -H "Content-Type: application/json" -d  '{"age":"21343","password":"password"}' http://192.168.2.127:8888/json.php 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大