我想從網址獲取源代碼。但我發現的所有東西都被棄用,或者它不是我想要的,所以我仍然在尋找,但我什麼也沒找到。在Android中,如何將HTML源代碼轉換爲字符串?
推薦使用:
HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
HttpGet httpget = new HttpGet("http://yoururl.com"); // Set the action you want to do
HttpResponse response = httpclient.execute(httpget); // Executeit
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent(); // Create an InputStream with the response
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) // Read line by line
sb.append(line + "\n");
String resString = sb.toString(); // Result is here
is.close(); // Close the stream
你能幫助我嗎?使用HttpClient的距離的Apache HTTP
你是什麼意思與soapAction?我沒有這個,所有的功能都被棄用了。 –
好的,謝謝,小心你將「HttpResponse」粘貼到變量上:) –
謝謝,請嘗試告訴我。 –