我无法从php // input获取请求参数,它总是返回空字符串。$ _POST也总是空的,我可以获取参数的唯一方法是使用$ _REQUEST,但我不确定这是否是解决此问题的正确方法。var_dump(file_get_contents("php://input"));返回:string(0)“”var_dump($_POST);返回:array(0){}var_dump($_REQUEST);返回:array(2){[“” ergerg“] => string(6)” ergerg“ [” regergerg“] => string(6)” ergreg“}我在邮递员中的要求如下:POST /api/ajax.php?ergerg=ergerg®ergerg=ergregresponseStatus:200 OKTime:192 msSize:236 Bajax.php<?phpinclude "config.php";$rest_json = file_get_contents("php://input");$obj = json_decode($rest_json);$request = $obj->request;if($request == 1){ $userData = mysqli_query($con, "select * from rows"); $response = array(); while ($row = mysqli_fetch_assoc($userData)) { $response[] = $row; } echo json_encode($response);}if($request == 2){ $platform = $data->platform; $container1 = $data->container1; $container2 = $data->container2; $ZPU1 = $data->ZPU1; $ZPU2 = $data->ZPU2; $reportId = $data->reportId; mysqli_query($con, "INSERT INTO rows(platform,container1,container2, ZPU1,ZPU2,reportId) VALUES('" . $platform . "','" . $container1 . "','" . $container2 . "','" . $ZPU1 . "','" . $ZPU2 . "','" . $reportId . "')"); echo "Insert successfully";}exit;在配置文件中,只有与mysql数据库的连接:config.php<?php$host = "localhost"; /* Host name */$user = "root"; /* User */$password = "password"; /* Password */$dbname = "dbname"; /* Database name */$con = mysqli_connect($host, $user, $password,$dbname);// Check connectionif (!$con) { die("Connection failed: " . mysqli_connect_error());}
1 回答
- 1 回答
- 0 关注
- 240 浏览
添加回答
举报
0/150
提交
取消