Simple interaction between the android client and the php service: simple interaction between the android client and php + mysql + apache to achieve log information storage.
The implementation principle is that the android client sends a request to the server log information, the server receives the information, connects to the database for storage, and returns the stored status to the client.
Server:
First, create a database named testlog in mysql, which contains a log_info table that records information such as LogCategory, System, Executor, and Action.
Create a php project testlog under the php virtual directory and create the conn. php and log_deal.php files.
'; $ 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" ;}?>
The server has been built.
Android client:
You can write the layout as needed.
The following is the main code:
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", "System name"); params. add (new BasicNameValuePair ("LogCategory", "LOG level"); 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(.exe cute (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 ();}}}
All right, the simple client post data to the php server storage function has been completed.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.