gpt4 book ai didi

android - 将此技术用于 android 请求/响应是否安全?

转载 作者:行者123 更新时间:2023-11-30 03:30:49 25 4
gpt4 key购买 nike

我只是想知道这是在 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();
}
}

最佳答案

您必须使用threadAsynctask 进行网络相关操作。

 HttpResponse http_response = http.execute(http_get);  

在 Honeycomb 之后你会得到 NetworkOnMainThreadException。使用 AsyncTask 或使用线程`。

http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

对于异步任务

http://developer.android.com/reference/android/os/AsyncTask.html

注意:您不能从后台线程更新用户界面。您可以在 ui 线程上更新 ui。

关于android - 将此技术用于 android 请求/响应是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17509647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com