- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个 Android 登录应用程序,可以从用户那里获取用户名和密码。我想将用户名和密码发送到 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); ?>
Controller :
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);
}
}
通过在浏览器中输入以下网址,此代码可以很好地工作,但在 Android 应用程序中不起作用!“本地主机/ar/用户/登录?名称=m_sepehri&密码=111”有人可以帮助我吗?
最佳答案
您正在使用 httppost,但附加您的数据名称并传递到 url 本身。将 AsyncTask 与 List 一起使用,如下所示:
private class MyAsyncTask extends AsyncTask<String, Integer, Double> {
@Override
protected Double doInBackground(String... params) {
// TODO Auto-generated method stub
postData(name1, email1, password1, mobile1);
return null;
}
protected void onPostExecute(Double result) {
pb.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(),
"Account Activated Login To MyGenie",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(RegisterActivity.this,
LoginActivity.class);
startActivity(intent);
}
protected void onProgressUpdate(Integer... progress) {
pb.setProgress(progress[0]);
}
public void postData(String name, String email, String password,
String mobile) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://yoursite.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", name));
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs
.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("mobile", mobile));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
关于java - 将数据从 Android 应用程序发送到 cakephp 的whith url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18250896/
您好,我有一个产品表(是实际的书籍),我需要它来创建复杂的搜索 我有一个用于搜索的文本框因此,当我在该文本框中写入关键字时,我需要返回以下产品 the title LIKE the keyword
文档说 UIDocumentInteractionController 允许使用已安装的应用程序隐式打开文件(UTI 属性为 nil),但不是 native 的。 UIDocumentInteract
我做错了什么? print('script executed in {time}{1:.2f} seconds'.format(time=elapsed_time)) 我得到: IndexError:
我有一个 Web 应用程序,用户必须在其中登录。密码存储在 LDAP 服务器中。有关 LDAP 服务器的所有信息都作为外部 jndi 资源存储在应用程序服务器 (glassfish) 中。所以我的应用
我有 Youtube Api v3 的问题。问题是想从上传的视频中获取信息,在为视频执行检索信息时,我收到错误403 Forbidden。 如果我运行我使用的 url,浏览器会返回 Json me 和
我的“controller.py”脚本 #!/usr/bin/env python # -*- coding: utf-8 -*- import os def application(environ,
我是一名优秀的程序员,十分优秀!