OpenData

  
售價: NT$10
Android 如何使用 GET & POST 取得資料

1.首先你要建立一個 HttpClient 物件: HttpClient httpclient = new DefaultHttpClient(); 2.接著建立 HttpGet 物件並傳入網址: HttpGet httpget = new HttpGet(strurl); 3.當 HttpClient 執行 Get 任務後,會傳回 HttpResponse: HttpResponse response = httpclient.execute(httpget); 4.接下來就可以取得資料實體: HttpEntity httpEntity = response.getEntity(); 5.你可以把它轉成字串來使用: String str = EntityUtils.toString(httpEntity,”UTF-8”); 以上就是Get的基本操作。