【问题标题】:Simplest way to grab echo from PHP file and use it in Android Studio project?从 PHP 文件中获取回显并在 Android Studio 项目中使用它的最简单方法?
【发布时间】:2017-10-28 04:04:28
【问题描述】:

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

我想知道是否可以从主要活动中创建基本上将读取的语句“如果 php 文件回显“成功”则下一页的 startActivity。我相信我需要 HTTPURLClient,但是,有没有办法“在短短几行中从 php 文件中检索回声,并将回声设置为等于 java 中的字符串变量,这样我就可以比较 if 语句来查看它是否“成功”?大多数 HTTPClient 教程都是要连接的代码页面

【问题讨论】:

标签: java php android mysql


【解决方案1】:

我使用了这个库https://github.com/kosalgeek/generic_asynctask。 使用这个库的代码基本格式是这样的:

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");

更多内容请参考链接。

【讨论】:

    猜你喜欢
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2015-08-25
    • 2015-08-17
    • 1970-01-01
    相关资源
    最近更新 更多