本文介绍了在Android中,如何获得HTML源代码code为一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个URL获得源$ C ​​$ C。但是,所有的事情我才发现,是德precated或者它没有我想要什么,所以我还在寻找,但我觉得没什么。

I would like to get the source code from an url. But all things i found, is deprecated or it's no what i want, so i still searching, but i find nothing.

德precated:

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客户端将是更快,更好。我可以推荐你这一点。

Use alternative http client it will be faster and better. I can recommend you this.

这篇关于在Android中,如何获得HTML源代码code为一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 09:09