我有一个 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/