我只是想知道这是否是在 android 中进行交流的好方法,还是有更安全、更好的方法?
btnInsert.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0)
{
//Create the request
**String url** = "http://10.0.2.2:80/practice/mysql_demo/inserting.php?";
url = url + "txtName=" + txtName.getText().toString() + "&";
url = url + "txtAge=" + txtAge.getText().toString() + "&";
url = url + "txtAddress=" + txtAddress.getText().toString() + "&";
url = url + "txtContact=" + txtContact.getText().toString() + "&";
url = url + "txtOtherInformation=" + txtOtherInformation.getText().toString();
**executeQuery(url)**;
selectRecords(lstStudents);
}
});
**public void executeQuery(String url)**
{
//execute the URL, and get the result
try
{
HttpClient http = new DefaultHttpClient();
HttpGet http_get = new HttpGet(url);
HttpResponse http_response = http.execute(http_get);
HttpEntity http_entity = http_response.getEntity();
BufferedReader br = new BufferedReader(
new InputStreamReader(http_entity.getContent()));
String result = br.readLine();
Toast.makeText(PHPDemo.this, result, Toast.LENGTH_LONG).show();
}
catch (Exception ex)
{
Toast.makeText(PHPDemo.this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}