Android的web数据交互、储存,都用什么技术实现
Android的web数据交互、存储,都用什么技术实现?
简而言之就是像那种简单的一个Android应用
1、用户注册
2、然后登陆
3、用户填写基本信息存储到数据库
问题1、用户账号、信息数据保存在哪里?(远程有个服务器端吧?)
问题2、如果有服务器,服务器是什么形式,如何访问数据库?
问题3、需要的工具?(开发包或者是环境或者是什么之类的)
请一一作答我的问题,因为刚接触不久,没有实战经验,理解上有模糊,大神请帮忙!
急!跪谢!
------解决方案--------------------
远程数据库可以是各种形式啊这和android没关系,就直接用httpclient或者socket传数据就OK了
------解决方案--------------------
你设计2个WEB页面,一个页面有账号和密码输入框,提交的时候跳到第二个页面显示出来或者数据插入到数据库,成功后第二个页面就可以算作webservice接口了,手机上只要模拟第一个页面输入账号密码跳转到第二个页面即可。
手机一点点你得按你的要求改改,主要使用httpclient httprespone
public static String uploadSubmit(String url, Map<String, String> param,
File file) throws Exception {
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MultipartEntity();
if (param != null && !param.isEmpty()) {
for (Map.Entry<String, String> entry : param.entrySet()) {
if (entry.getValue() != null
&& entry.getValue().trim().length() > 0) {
entity.addPart(entry.getKey(),
new StringBody(entry.getValue()));
}
}
}
// 添加文件参数
if (file != null && file.exists()) {
entity.addPart("file", new FileBody(file));
}
post.setEntity(entity);
HttpClient httpClient=new DefaultHttpClient();
HttpResponse response = httpClient.execute(post);
//String serverResponse = EntityUtils.toString(response.getEntity()); 这样可以直接获得,但是下面的代码可以获得复杂的数据
int stateCode = response.getStatusLine().getStatusCode();
StringBuffer sb = new StringBuffer();
if (stateCode == HttpStatus.SC_OK) {
HttpEntity result = response.getEntity();
if (result != null) {
InputStream is = result.getContent();
BufferedReader br = new BufferedReader(
new InputStreamReader(is));
String tempLine;
while ((tempLine = br.readLine()) != null) {
sb.append(tempLine);
}
}
}
post.abort();
return sb.toString();
}
简而言之就是像那种简单的一个Android应用
1、用户注册
2、然后登陆
3、用户填写基本信息存储到数据库
问题1、用户账号、信息数据保存在哪里?(远程有个服务器端吧?)
问题2、如果有服务器,服务器是什么形式,如何访问数据库?
问题3、需要的工具?(开发包或者是环境或者是什么之类的)
请一一作答我的问题,因为刚接触不久,没有实战经验,理解上有模糊,大神请帮忙!
急!跪谢!
------解决方案--------------------
远程数据库可以是各种形式啊这和android没关系,就直接用httpclient或者socket传数据就OK了
------解决方案--------------------
你设计2个WEB页面,一个页面有账号和密码输入框,提交的时候跳到第二个页面显示出来或者数据插入到数据库,成功后第二个页面就可以算作webservice接口了,手机上只要模拟第一个页面输入账号密码跳转到第二个页面即可。
手机一点点你得按你的要求改改,主要使用httpclient httprespone
public static String uploadSubmit(String url, Map<String, String> param,
File file) throws Exception {
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MultipartEntity();
if (param != null && !param.isEmpty()) {
for (Map.Entry<String, String> entry : param.entrySet()) {
if (entry.getValue() != null
&& entry.getValue().trim().length() > 0) {
entity.addPart(entry.getKey(),
new StringBody(entry.getValue()));
}
}
}
// 添加文件参数
if (file != null && file.exists()) {
entity.addPart("file", new FileBody(file));
}
post.setEntity(entity);
HttpClient httpClient=new DefaultHttpClient();
HttpResponse response = httpClient.execute(post);
//String serverResponse = EntityUtils.toString(response.getEntity()); 这样可以直接获得,但是下面的代码可以获得复杂的数据
int stateCode = response.getStatusLine().getStatusCode();
StringBuffer sb = new StringBuffer();
if (stateCode == HttpStatus.SC_OK) {
HttpEntity result = response.getEntity();
if (result != null) {
InputStream is = result.getContent();
BufferedReader br = new BufferedReader(
new InputStreamReader(is));
String tempLine;
while ((tempLine = br.readLine()) != null) {
sb.append(tempLine);
}
}
}
post.abort();
return sb.toString();
}