【问题标题】:Talking to PHP get commands from Android app与 PHP 交谈从 Android 应用程序获取命令
【发布时间】:2016-02-24 11:11:51
【问题描述】:

我有一个 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 数组。我检查了网址,它是正确的。我究竟做错了什么?谢谢!

【问题讨论】:

  • 参考this问题,这对你有帮助
  • 这是 $this->input->get();除非你的控制器中有一个名为 get 的方法。

标签: php android codeigniter url


【解决方案1】:

你的代码应该是这样的 对于您的 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2012-04-21
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    相关资源
    最近更新 更多