1
如何創建一個Http連接來檢索網頁內容到我的android?請爲此發佈示例代碼。Android中的HTTP連接
如何創建一個Http連接來檢索網頁內容到我的android?請爲此發佈示例代碼。Android中的HTTP連接
其HTTP客戶端,例如得到它可能有助於在預覽
HttpClient client;
HttpGet method;
String url;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
url="enter your url here";
method = new HttpGet(url);
try {
client.execute(method);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setContentView(R.layout.main);
}
public void executeHttpGet() throws Exception {
BufferedReader in = null;
try {
client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = client.execute(method);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
它訪問XML數據我有此例嘗試。
作爲一個手機中的XML數據,所以如何轉換成真正的數據與XML標籤? – mohammedsuhail 2010-08-31 05:42:36
我hvnt試圖在這裏查找我認爲這對你有幫助。 http://www.ibm.com/developerworks/opensource/library/x-android/index.html – 2010-08-31 06:08:48
感謝您的回答 – mohammedsuhail 2010-09-02 06:54:18