您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

android客户端和php服务简单交互

2024/4/28 11:15:45发布5次查看
android客户端和php+mysql+apache搭建之间的简单交互,实现log信息存储。
实现原理就是android客户端发送请求,传给服务器log信息,服务器收到这些,连接数据库进行存储,并将存储后的状态返回给客户端。
服务器端:
先在mysql里面建一个testlog的数据库,里面有一个log_info表,记录了logcategory,system,executor,action等信息。
在php的虚拟目录下新建一个php项目testlog,创建conn.php和log_deal.php文件。

服务器搭建完成。
android客户端:
布局随意写一下就ok了
下面是主要代码:
class sendloghandler implements runnable{ @override public void run() { try { string url = http://localhost/testlog/log_deal.php; string result = null; boolean issendsucceed = false; httppost httprequest = new httppost(url); list params = new arraylist(); params.add(new basicnamevaluepair(system, 系统名称)); params.add(new basicnamevaluepair(logcategory, log等级)); params.add(new basicnamevaluepair(executor, 操作人)); params.add(new basicnamevaluepair(action, 发生了什么事)); httprequest.setentity(new urlencodedformentity(params, http.utf_8)); httpresponse httpresponse = new defaulthttpclient().execute(httprequest); int statecode = httpresponse.getstatusline().getstatuscode(); if (statecode == 200){ httpentity httpentity = httpresponse.getentity(); result = entityutils.tostring(httpentity); } if (result.equals(succeed)){ issendsucceed = true; } message msg = new message(); msg.what = 2; msg.obj = issendsucceed; handler.sendmessage(msg); } catch (exception e){ e.printstacktrace(); } } }
好了,简单的客户端post数据到php服务器端存储的功能已经完成了。
版权声明:本文为博主原创文章,未经博主允许不得转载。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录