我想从网址获取源代码。但我发现的所有东西都已被弃用,或者不是我想要的,所以我仍在搜索,但我什么也没找到。
已弃用:
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
你能帮我吗?
最佳答案
使用替代的http客户端会更快更好。我可以向您推荐这个。
关于java - 在Android中,如何将HTML源代码转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31351517/