php - 与 PHP 对话从 Android 应用程序获取命令

标签 php android codeigniter url

我有一个 Android 应用程序,正在尝试将数据发送到服务器上的 PHP。服务器使用

获取 php 数据
$this->get('uname');
$this->get('pass');

如果重要的话,我们会使用 codeigniter

Async 方法内部的 Java 代码,我目前拥有的是

InputStream response = null;
URLConnection connection = new URL(urls[0]).openConnection();
connection.setRequestProperty("uname" , Username);
connection.setRequestProperty("pass", Password);
response = connection.getInputStream();

当我运行它时,代码总是返回 null 但它应该以任何一种方式返回一个 JSON 数组。我已经检查了 URL,它是正确的。我究竟做错了什么?谢谢!

最佳答案

你的代码应该是这样的 对于你的 android 端,正如@Ichigo Kurosaki 在 Sending POST data in Android 提到的那样

对于 Codeigniter 端,考虑到您的函数名称是 user_login

function user_login(){
$uname = $this->input->get_post('uname'); //get_post will work for both type of GET/POST request
$pass =  $this->input->get_post('pass');
$result=$this->authenticate->actLogin($uname,$pass  ); //considering your authenticating user and returning 1,0 array as success/failure
$this->output
    ->set_content_type('application/json')
    ->set_output(json_encode($result));
exit;
}

关于php - 与 PHP 对话从 Android 应用程序获取命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33852530/

相关文章:

用于检测分页的 PHP 正则表达式

android - 在 Android ListView 中编辑项目

通过魔术方法访问的 PhpStorm 字段

php - Codeigniter -- _render_page() 未定义

php - mySQL 使用数据表进行搜索

php - 抱歉,无法找到您要查找的页面。硅胶错误

php - 使用 PHP 和 JSON 将数组插入 MySQL 数据库

php - 使用$ _POST值的简单“插入表”

android - 调用对话结果的 Activity

microsoft-metro - 我想为我的 android 应用程序设计一个 metro 风格的用户界面