The simple interaction between the Android client and the Php+mysql+apache build allows the log information to be stored.
The realization principle is that the Android client sends the request, passes the server log information, the server receives these, connects the database to store, and returns the stored state to the client.
Server-side:
First in MySQL built a testlog database, there is a log_info table, recorded logcategory,system,executor,action and other information.
Create a new PHP project Testlog in the PHP virtual directory, creating the conn.php and log_deal.php files.
<?phpinclude_once (' conn.php ');//echo ' $_post receive:</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"; }? >
Server Setup is complete.
Android Client:
Layout feel free to write it.
Here's the main code:
Class Sendloghandler implements runnable{@Override public void Run () {try {Stri ng 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", "Systems Name")); Params.add (New Basicnamevaluepair ("Logcategory", "Log Rank")); Params.add (New Basicnamevaluepair ("Executor", "operator")); Params.add (New Basicnamevaluepair ("Action", "what happened"); Httprequest.setentity (New urlencodedformentity (params, HTTP. Utf_8)); HttpResponse HttpResponse = new Defaulthttpclient (). Execute (HttpRequest); int statecode = Httpresponse.getstatusline (). Getstatuscode (); if (statecode = =) {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 (); } } }
Well, the simple client post data to PHP server-side storage has been completed.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Simple interaction between Android client and PHP service