我在localhost上使用xampp将数据库与phpliteadmin连接起来。现在我必须从localhost检索数据并更新它..所以任何1都可以帮助我解决这个问题.. ??
答案 0 :(得分:2)
好的我有一个函数可以将一些数据发送到本地主机并从那里检索一些数据 使用此方法进行沟通: -
public void postData() throws Exception {
postData=et.getText().toString(); //some value
HttpClient httpclient = new DefaultHttpClient(); // connection
HttpPost httppost = new HttpPost("http://192.168.1.21/default.php"); //ip of your local host and php file!
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("msg", ""+str));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
ResponseHandler<String> responseHandler=new BasicResponseHandler(); // to get the response printed there
String responseBody = httpclient.execute(httppost, responseHandler); // here we are recieving values.
Toast.makeText(this, responseBody, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
}
}
你可以用这个php编码发送和检索值: -
<?php
include ('MCrypt.php'); //this my encryption example
$thename=$_POST["msg"]; //get values from there using post and "msg" must be same on both side!
$mcrypt = new MCrypt();
$decrypted = $mcrypt->decrypt($thename);
echo("Your Encrypted String:--".$thename."\n"); // this line will be sent to android and will be recived in String Response;
echo("Your Decrypted String:--".$decrypted);
?>