Java 从PHP文件中获取echo并在Android Studio项目中使用它的最简单方法?

Java 从PHP文件中获取echo并在Android Studio项目中使用它的最简单方法?,java,php,android,mysql,Java,Php,Android,Mysql,在android studio项目中,我正在创建一个具有登录功能的应用程序。使用的PHP页面连接到数据库,并有一个带有POST变量的select语句。如果变量“username”和“password”都在表中的一行中,则表示用户具有访问权限,因此返回“Success”的回显 我想知道,在主要活动中,我是否可以创建一些语句,这些语句基本上会读为“如果php文件响应”Success“,然后开始下一页的活动。我相信我需要HTTPURLClient,但是,有没有一种方法可以“检索”呢“将php文件中的e

在android studio项目中,我正在创建一个具有登录功能的应用程序。使用的PHP页面连接到数据库,并有一个带有POST变量的select语句。如果变量“username”和“password”都在表中的一行中,则表示用户具有访问权限,因此返回“Success”的回显

我想知道,在主要活动中,我是否可以创建一些语句,这些语句基本上会读为“如果php文件响应”Success“,然后开始下一页的活动。我相信我需要HTTPURLClient,但是,有没有一种方法可以“检索”呢“将php文件中的echo缩短几行,并将echo设置为java中的字符串变量,以便我可以执行比较if语句以查看它是否“成功”?大多数HTTPClient教程都是连接的代码页

我使用了这个库。 使用此库的代码的基本格式如下:

HashMap post = new HashMap();
post.put("txtName", variablename); // the first argument is the column name in your html file that refers to the username
post.put("txtPass", variablepass);// the first argument is the column name in your html file that refers to the password
PostResponseAsyncTask readData = new PostResponseAsyncTask(this, post,
    new AsyncResponse() {
        @Override
        public void processFinish(String s) {
            //s is the value that you get from the php execution so if you want to check for the word success you say:
       if(s.equals("success")){
           //do something
          }
        }
    });
readData.execute("http://yoursite.com/getdata.php");

请参考链接了解更多信息。

在询问堆栈溢出之前,最好先对您的主题进行一些研究。请看这个