android - 在 android 4.1.2 中将数据从 android 设备发送到服务器

标签 android http

我的应用程序适用于 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 所以你应该使用 AsyncTaskRunOnUiThread向服务器发送数据的方法

用于实现异步任务

Link1 Link2 Link3 Link4

希望对你有所帮助。

关于android - 在 android 4.1.2 中将数据从 android 设备发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19971148/

相关文章:

android - Android 4.4 中的自定义 View 构造函数在 Kotlin 上崩溃,如何修复?

Java post http 请求(express)REST api

javascript - javascript中的HTTP Content-Length header 计算

Python与SSL——违反协议(protocol)发生EOF

C#发送POST请求并接收303状态码

android - Android中调试native代码的工具有哪些

Android 操作栏可检查菜单项无法正常工作/显示?

Android Studio Gradle : how to configure buildTypes, 并在构建时检查哪种构建类型?

android - AppCompatActivity 不对操作栏使用 colorPrimary?

http - 在 HTTP 日志中,我看到了 OPTIONS、GET、OPTIONS、POST 为什么?