POST工作几次

时间:2016-07-06 16:46:21

标签: php android mysql http-post

我遇到了这个难以谷歌的错误
我正在尝试使用POST将MySQL数据库连接到Android应用程序

enter image description here

这是我的index_app.php

<?php
$username = $_POST['username'];
$password = $_POST['password'];

$res = mysqli_query($con,"SELECT * FROM users WHERE username='$username' and password = '$password'");
mysqli_store_result($con);
if(mysqli_num_rows($res) == 0)
{
    $res = mysqli_query($con,"SELECT * FROM users WHERE username='$username'");
    if (mysqli_num_rows($res) == 0)
        echo "No User Found";
    else
        echo "password incorrect";
}
else
{
    echo "true";
}
?>

当我尝试通过hurl.it发送帖子请求时,我会得到预期的结果。但是通过[requestmaker.com] [3]发送它们会得到错误的结果。

现在,当我尝试在我的应用中获得结果时,我得到的结果与requestmaker.com类似。
这是MyApp的代码

public class LoginBtnOnClick extends AsyncTask<String,Void,String>
{
    String userName, passWord;
    TaskDoneListener taskDoneListener;

    public void setTaskDoneListener(TaskDoneListener taskDoneListener)
    {
        this.taskDoneListener = taskDoneListener;
    }

    public LoginBtnOnClick(String userName, String passWord)
    {
        this.userName = userName;
        this.passWord = passWord;
    }

    public String connect() throws IOException
    {
        URL url = new URL("http://ezcloud.esy.es/ezCloudWebsite/index_app.php");
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setRequestMethod("POST");
        Log.e("asda", "connect: "+userName + " "  + passWord);
        httpURLConnection.setRequestProperty("username", userName);
        httpURLConnection.setRequestProperty("password", passWord);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setDoInput(true);
        InputStream is = httpURLConnection.getInputStream();
        return isToString(is);
    }

    public String isToString(InputStream is) throws IOException
    {
        BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf-8"));
        StringBuilder sb = new StringBuilder();
        String line = r.readLine();
        while (line != null && !line.isEmpty())
        {
            sb.append(line);
            line = r.readLine();
        }
        Log.d("line", "isToString: "+sb.toString());

        return sb.toString();
    }

    @Override
    protected String doInBackground(String... params)
    {
        try
        {
            return connect();
        }
        catch (IOException e)
        {
            Log.e("exception", "doInBackground: "+e);
            return null;
        }
    }

    @Override
    protected void onPostExecute(String s)
    {
        super.onPostExecute(s);
        taskDoneListener.onTaskDone(s);
    }

    public interface TaskDoneListener
    {
        String onTaskDone(String str);
    }
}

我正在

  

找不到用户

即使是正确的用户名和密码

0 个答案:

没有答案