0
我有這個asynctask.I需要連接設備與web server.Need發送一個JSON Arry並接收JSON數組。我可以使用httpUrlConnection嗎?或httpClient。 httpClient是否支持最新版本的Android?如何使用AsyncTask連接Android設備和web服務器
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(棉花糖)HttpClient不支持。 – Anil
http://developer.android.com/training/basics/network-ops/connecting.html –