【发布时间】:2014-05-04 11:28:56
【问题描述】:
我正在尝试将数据从 Android 应用程序发送到服务器....但是单击保存按钮会导致 android.os.NetworkOnMainThreadException 并且应用程序停止。
请问有人可以帮忙吗?
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://farahkhan.byethost15.com/try.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", "01"));
nameValuePairs.add(new BasicNameValuePair("email", signupemailString));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
signupemail.setText(""); //reset the message text field
Toast.makeText(getBaseContext(),"Sent",Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】:
标签: android networkonmainthread