httpclient的到网页源码

使用httpclient4.3.4版本

/**

* 得到网页源码

* @param response  响应
* @param charset     编码
* @return
* @throws IOException
*/
public static String getHtml(CloseableHttpResponse response, String charset)
throws IOException {
String html = null;
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = entity.getContent();
html = IOUtils.toString(inputStream, charset);//使用Apache的commons-io-2.4.jar
}
return html;
}

猜你喜欢

转载自blog.csdn.net/u011585735/article/details/32703017