0

localhost で xampp を使用してデータベースを phpliteadmin に接続しました。今、私はローカルホストからデータを取得し、それを更新する必要があります..だから、この問題から私を助けることができる..??

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 に答える