0

我已经使用本地主机上的 xampp 将数据库与 phpliteadmin 连接起来。现在我必须从 localhost 检索数据并更新它.. 所以任何 1 都可以帮助我解决这个问题..??

4

1 回答 1

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);


?>
于 2013-03-19T10:28:55.177 回答