2015-08-31 133 views
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; 

    } 
+0

6.0(棉花糖)HttpClient不支持。 – Anil

+0

http://developer.android.com/training/basics/network-ops/connecting.html –

回答

0

您應該使用谷歌自己的排球庫進行網絡調用並處理模型類中的響應數據。這是最模塊化的方法。官方文檔請參考this鏈接。

相關問題