我要开发Android应用程序,因为我想知道如何在远程服务器中存储和检索数据. [英] I develop android application in that i want to know how to store and retrieve data in remote server.

查看:63
本文介绍了我要开发Android应用程序,因为我想知道如何在远程服务器中存储和检索数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我开发了一个Android应用程序,因为我有一个登录和注册表格,其中包含该字段的名称,密码,电子邮件,电话号码.填满了用户.当他们填写注册表格后,数据将使用php脚本存储在远程服务器中.之后,将使用名称"和密码"进行登录.

我是android网络服务的新手,所以请帮助我找到这个....
谢谢&Regards ....

Hi, I develop one android application in that i have one login and registration form in that name, password, email, phno that are the field. which fill up bye the user. When they fill registration form then data will be store in the remote server using php script. And after that Name and password will be use to login.

i am new to web service in android so please help me to find this....
Thanks & Regards....

推荐答案

最简单的答案是在服务器上调用PHP脚本,然后通过GET将参数提交给它(例如尽管不推荐使用,但作为注册表格,很可能会有私人信息).

如果您想正确执行此操作,则应打开从Android应用程序到服务器的加密(HTTPS)连接,并安全地提交注册信息.现在,我目前没有HTTPS示例可提供给您,但是我可以向您展示一种简单的方法将数据发布到脚本的url(不安全):

The simplest answer would be to call the PHP script on the server, and submit the parameters to it via a GET for instance (although NOT recommended, as being a reg form, there will most likely be private information).

If you want to do it properly, you should open an encrypted (HTTPS) connection from your Android application to the server, and submit the registration info securely. Now, I have no HTTPS example to give you at the moment, but I can show you a simple way of POSTing data to your script''s url (unsecurely):

String result = null;
InputStream is = null;
String url = "http://localhost/your_php_script_url.php";

//Create the request parameters that will be sent to the server
ArrayList<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("param1_name", "param1_value"));
params.add(new BasicNameValuePair("param2_name", "param2_value"));
params.add(new BasicNameValuePair("param2_name", "param2_value"));

//Execute the HTTP POST and get the response as an InputStream
try {
	HttpClient httpclient = new DefaultHttpClient();
	HttpPost httppost = new HttpPost(url);
	httppost.setEntity(new UrlEncodedFormEntity(params));
	HttpResponse response = httpclient.execute(httppost);
	HttpEntity entity = response.getEntity();

	is = entity.getContent();
} catch (Exception e) {
	Log.e("Error", "Error in http connection " + e.toString(), e);
}

//Convert response to String and output it to Android console
try {
	BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
	StringBuilder sb = new StringBuilder();
	String line = null;
	while ((line = reader.readLine()) != null) {
		sb.append(line + "\n");
	}
	is.close();
			
	Log.d("Server response", sb.toString());
} catch (Exception e) {
	Log.e("Error", "Error converting result " + e.toString(), e);
}
</namevaluepair></namevaluepair>



本示例使用Android中默认的Apache HTTP库.只需用脚本中所需的内容替换模拟参数和变量,就可以了.

而且,这本身并不是Web服务(尽管可以说它是RESTful完成的).如果您需要调用适当的Web服务(例如SOAP),那么只需对它进行Google搜索即可.



This example uses the default Apache HTTP library found in Android. Just replace the mock parameters and variables with what you need in the script, and should be good to go

Also, this is not a webservice per se (although it could be argued that it''s done RESTfully). If you need to call a proper webservice (eg SOAP), well, just Google it. Here it is[^]


这篇关于我要开发Android应用程序,因为我想知道如何在远程服务器中存储和检索数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆