android客户端跟php服务简单交互
android客户端和php服务简单交互
android客户端和php+mysql+apache搭建之间的简单交互,实现log信息存储。
实现原理就是android客户端发送请求,传给服务器log信息,服务器收到这些,连接数据库进行存储,并将存储后的状态返回给客户端。
服务器端:
先在mysql里面建一个testlog的数据库,里面有一个log_info表,记录了LogCategory,System,Executor,Action等信息。
在php的虚拟目录下新建一个php项目testlog,创建conn.php和log_deal.php文件。
<?php include_once('conn.php'); //echo '$_POST接收:</br>'; $System = $_POST['System']; $LogCategory = $_POST['LogCategory']; $Executor = $_POST['Executor']; $Action = $_POST['Action']; $sqlstr = "insert into log_info(System,LogCategory,Executor,Action,CreateTime) values('".$System."','".$LogCategory."','".$Executor."','".$Action."','".date('Y-m-d H:m:s')."')"; if (mysql_query($sqlstr)){ echo "succeed"; } else { die(mysql_error()); echo "error"; }?>
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(); } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The Executor interface provides a task execution mechanism, and ThreadPool is its implementation, managing the thread pool to execute tasks. ThreadPool is created using the Executors tool class, such as newFixedThreadPool(), and uses the execute() method to submit tasks. In a practical case, ExecutorService and ThreadPool are used to calculate the sum of squares of numbers to demonstrate the use of parallel programming. Considerations include balancing thread pool size and number of tasks, avoiding exceptions being thrown, and closing ThreadPool after use.

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

The advantages provided by the Executor framework in Java concurrent programming include: simplified thread management and simplified thread operations through thread pool management. Flexible task management provides customized methods to control task execution. Scalability and performance, automatically adjusting thread pool size to support large-scale task processing. Simplify error handling and improve application stability by centrally handling task execution exceptions.

Thread Pool Class Diagram The most commonly used Executors implementation to create a thread pool and use threads mainly uses the classes provided in the above class diagram. The class diagram above includes an Executor framework, which is a framework that schedules execution and controls asynchronous tasks based on a set of execution strategy calls. The purpose is to provide a mechanism that separates task submission from how tasks are run. It contains three executor interfaces: Executor: a simple interface for running new tasks ExecutorService: extends Executor, adding methods for managing the executor life cycle and task life cycle ScheduleExcutorService: extends ExecutorSe

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。

图片消失如何解决先是图片文件上传$file=$_FILES['userfile']; if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

图片消失如何解决先是图片文件上传$file=$_FILES['userfile']; if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'
