我的应用程序适用于 android 2.3.3,但它在 android 4.1.2 中强制关闭 下面是我将数据从 Android 设备发送到服务器的代码。
HttpEntity entity;
HttpClient client = new DefaultHttpClient();
String url ="http://67.23.166.35:80/android/insertv2.php";
HttpPost request = new HttpPost(url);
StringEntity se = new StringEntity(datatoServer);
se.setContentEncoding("UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
entity = se;
request.setEntity(entity);
HttpResponse response = client.execute(request);
entity = response.getEntity();
最佳答案
检查以下链接,伙计,
我假设你得到了 NetworkOnMainThreadException 所以你应该使用 AsyncTask和 RunOnUiThread向服务器发送数据的方法
用于实现异步任务
希望对你有所帮助。
关于android - 在 android 4.1.2 中将数据从 android 设备发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19971148/