【发布时间】:2015-11-25 03:13:59
【问题描述】:
我有这个异步任务。我需要将设备与 Web 服务器连接。需要发送 JSON Arry 并接收 JSON 数组。我可以使用 httpUrlConnection 吗?或 httpClient。 httpClient 是否支持最新版本的 Android?
class background_thread extends AsyncTask<JSONArray, Void, Boolean> {
protected Boolean doInBackground(JSONArray... params) {
//connect with server side php script
String UR = "127.0.0.1/abc/index.php";
try {
URL url = new URL(UR);
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
json_array=json_encode();
conn.setDoOutput(true);
conn.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(conn.getOutputStream());
writeStream(out);
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
return true;
}
【问题讨论】:
-
6.0(Marshmallow) HttpClient 不支持。
标签: android android-activity android-asynctask android-json