简体   繁体   English

php无法读取http post请求正文

[英]php can't read http post request body

I've been stuck in this problem for two weeks.我已经被这个问题困住了两个星期。 I have a flutter app and I'm trying a simple login with a username and password and I'm checking if there's a match to the username and password in the data base.我有一个 flutter 应用程序,我正在尝试使用用户名和密码进行简单登录,我正在检查数据库中的用户名和密码是否匹配。 I'm using php as a back-end but it seems that php can't see the post request body at all.我使用 php 作为后端,但似乎 php 根本看不到 post 请求正文。 I tried it at postman and even if the username and password are correct it always gives me "Invalid Username or password please try again".我在邮递员那里试过,即使用户名和密码正确,它也总是给我“无效的用户名或密码,请再试一次”。 I think that it returns an empty response but I don't know why.我认为它返回一个空响应,但我不知道为什么。

the status code= 200.状态代码 = 200。

php code: php代码:

    <?$con = include "conn.php";
    $json = file_get_contents('php://input');
   $obj = json_decode($json);

    $username = $obj['username'];

  $password = $obj['password'];

  $loginQuery = "select * from user where username = '$username' andpassword = '$password' ";

 $check = mysqli_fetch_array(mysqli_query($con,$loginQuery));

if(isset($check)){
    
     $onLoginSuccess = 'Login Matched';
     
     $SuccessMSG = json_encode($onLoginSuccess);
     
     echo $SuccessMSG ; 
 
 }
 
 else{
    $InvalidMSG = 'Invalid Username or Password Please Try Again' ;
     
    $InvalidMSGJSon = json_encode($InvalidMSG);
     
     echo $InvalidMSGJSon ;
 
 }

 mysqli_close($con);
?>

Also when I print the $obj or $username to see what it has, it gives nothing.此外,当我打印 $obj 或 $username 以查看它有什么时,它什么也没给出。

Thanks if you made it so far and sorry for the long text.谢谢你,如果你做到了,对长文本感到抱歉。 i will be very thankful if someone save me.如果有人救我,我将非常感激。

I solved that.我解决了那个。 Basically I just created a new user table and it worked like magic.基本上我刚刚创建了一个新的用户表,它就像魔术一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM