提取时网络请求失败 - ReactNative

时间:2017-12-11 16:01:44

标签: php mysql react-native-android

我收到网络请求失败的wile身份验证。我使用ip地址而不是localhost。我在移动设备上运行我的应用程序。这是我的代码。在我看来,这是一个获取功能的错误。可能是file_get_contents('php:// input')这个函数的错误,因为我不明白这个php://输入是什么? LoginForm.js(保存在E:中)

      login = () =>{
    const {userEmail, userPassword} = this.state;

    fetch('http://192.168.0.104/fyp/login.php', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({

    u_email: userEmail,

    u_password: userPassword

  })

}).then((response) => response.json())
      .then((responseJson) => {
        alert(responseJson);

        // If server response message same as Data Matched
       if(responseJson === 'Data Matched')
        {

            //Then open Profile activity and send user email to profile
            this.props.navigation.navigate('Menu');

        }
        else{

          Alert.alert(responseJson);
        }

      }).catch((error) => {
        alert(error);
});

  }

*这是我的login.php(保存在localhost / fyp / login.php中)

    <?php

// Importing DBConfig.php file.
include 'DBConfig.php';

// Creating connection.
 $con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);

 // Getting the received JSON into $json variable.
 $json = file_get_contents('php://input');

 // decoding the received JSON and store into $obj variable.
 $obj = json_decode($json,true);

// Populate User email from JSON $obj array and store into $email.
$u_email = $obj['u_email'];

// Populate Password from JSON $obj array and store into $password.
$u_password = $obj['u_password'];

//Applying User Login query with email and password match.
$Sql_Query = "SELECT * FROM user where u_email='$u_email' and u_password='$u_password'";

// Executing SQL Query.
$check = mysqli_fetch_array(mysqli_query($con,$Sql_Query));


if(isset($check)){

 $SuccessLoginMsg = 'Data Matched';

 // Converting the message into JSON format.
$SuccessLoginJson = json_encode($SuccessLoginMsg);

// Echo the message.
 echo $SuccessLoginJson ; 

 }

 else{

 // If the record inserted successfully then show the message.
$InvalidMSG = 'Invalid Username or Password Please Try Again' ;

// Converting the message into JSON format.
$InvalidMSGJSon = json_encode($InvalidMSG);

// Echo the message.
 echo $InvalidMSGJSon ;

 }

 mysqli_close($con);
?>

* DBConfig.php

<?php
$HostName = "localhost";
$DatabaseName = "mydb";
$HostUser = "root";
$HostPass = "";

?>

Network Request Failed

0 个答案:

没有答案