我写了一个从用户那里获取用户名和密码的安卓登录应用程序。我想将用户名和密码发送到cakephp 应用程序的服务器。这是我的 android 代码:
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://10.0.2.2/ar/users/login?name="+name+"&password="+pass);
//Execute HTTP Post Request
response=httpclient.execute(httppost);
final ResponseHandler<String> responseHandler = new BasicResponseHandler();
result = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
JSONArray jArray;
jArray = new JSONArray(result);
JSONObject j =new JSONObject();
j = jArray.getJSONObject(0);
JSONObject json = j.getJSONObject("User");
text = json.getString("last_name");
我在布局中只写了这一行:
<?php echo $content_for_layout ?>
查看代码:
<?php echo json_encode($user); ?>
控制器:
function login() {
if(isset($this->params['url']['name']))
$data = $this -> User -> findByuser_name($this->params['url']['name']);
if ($data && $data['User']['password'] == ($this->params['url']['password'])) {
$this -> set('user', $data);
} else {
$this -> set('error', true);
}
}
通过在浏览器中输入下面的 url,此代码可以很好地工作,但不能在 android 应用程序中工作!"localhost/ar/users/login?name=m_sepehri&password=111" 有人可以帮助我吗?