- 浏览: 16878 次
- 性别:
- 来自: 广州
最新评论
Need Jar:
htmlunit-2.17-OSGi.jar
htmlunit-2.17-OSGi.jar
@SuppressWarnings({ "finally", "deprecation" }) public static String executeGet(String url,String host,String cookie) throws IOException { BufferedReader in = null; String content = null; int responseCode = 0; DefaultHttpClient client = new DefaultHttpClient(); try { HttpGet request = new HttpGet(); request.addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); request.addHeader("Accept-Language","zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4"); request.addHeader("Connection","keep-alive"); request.addHeader("Cookie",cookie); request.addHeader("Host",host); request.addHeader("Upgrade-Insecure-Requests","1"); request.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"); request.setURI(new URI(url)); HttpResponse response = client.execute(request); responseCode = response.getStatusLine().getStatusCode(); //System.out.println("Url: "+url+" Response = "+response.getStatusLine().getStatusCode()); int count=1; while(responseCode!=200 && count<=3){ count ++; System.out.println("--------call again......"); Thread.sleep(3000); client.close(); client = new DefaultHttpClient(); response = client.execute(request); responseCode = response.getStatusLine().getStatusCode(); } 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); } content = sb.toString(); }catch(Exception e){ e.printStackTrace(); } finally { if(in!=null) in.close(); if(client!=null) client.close(); return content; } }
发表评论
-
Maven install problem: Unexpected end of ZLIB input stream。
2018-03-08 12:58 596Maven install problem: Unexpect ... -
Call a java class from
2018-03-07 15:40 222中華人民共和國 -
Image Process
2017-10-31 09:08 161<div class="iteye-blog- ... -
mysql 存入 blob类型数据
2016-09-30 14:25 938String content = new String(bl ... -
java send email
2016-08-08 00:47 278static int port = 25; //smt ... -
phantomjs & casperjs install in l Fedora
2016-08-06 22:33 287phantomjs install in Fedora: ... -
Json String to Bean
2016-08-03 18:10 259<div class="iteye-blog- ... -
Java Read Html
2016-07-28 14:37 326Need Jar: jsoup-1.8.1.jar ... -
Java to Excel 2
2016-07-26 14:04 303Use Jar: poi-3.14-20160307.jar ... -
show process in mysql
2016-07-22 11:55 296SELECT * FROM INFORMATION_SCHEM ... -
Java to Excel
2016-07-15 16:14 268Java to Excel https://poi.apach ... -
HttpClient
2016-06-22 10:17 255Remark: set userAgent package ... -
Hibernate3 dynamicUpdate
2016-06-22 10:07 259@org.hibernate.annotations.Ent ... -
解決多線程派任務問題
2016-01-08 18:06 367解決多線程派任務問題: 使用: 每次只update 一條 ... -
daysBetween
2015-12-23 09:27 230public int daysBetween(Strin ... -
IntelliJ Idea – How to enable zoom of text by CTRL + Mouse wheel
2015-11-22 17:53 473IntelliJ Idea – How to ... -
List do sorting
2015-11-20 09:51 282Collections.sort(newList,new ... -
select multi tables join ---Hibernate
2015-10-29 14:05 601String hql = "from A a,B ... -
css 控制第二行字段縮進
2015-09-22 11:55 1155<div style="margin-left ... -
Hibernate: lazy load.
2015-08-05 12:27 371About lazy load, before you to ...
相关推荐
以上自己测试是可行的,直接拿过去导入即可,直接用main
httpclient
httpClient完整封装获取网页信息、数据的代码+httpclient.jar
HttpClient httpClient = new HttpClient(); // 设置 Http 连接超时为5秒 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); /* 2 生成 GetMethod 对象并设置参数 */ GetMethod ...
httpclient-4.5所需jar包,里面包含httpclient-4.5.jar等等10个必须的开发包。 1.commons-codec-1.9.jar 2.commons-logging-1.2.jar 3.fluent-hc-4.5.jar 4.httpclient-4.5.jar 5.httpclient-cache-4.5.jar 6....
httpclient.jar下载 包括code.jar包
赠送jar包:httpclient-4.5.6.jar; 赠送原API文档:httpclient-4.5.6-javadoc.jar; 赠送源代码:httpclient-4.5.6-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.6.pom; 包含翻译后的API文档:httpclient...
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods....
C# HttpClientHelper(HttpClient工具类) 包含 同步/异步请求 返回 string/泛型类型/Xml 及一个单例模式 的 SingleHelper 适合做爬虫
HttpClient的一个封装, HttpClient的一个封装
赠送jar包:httpclient-4.5.13.jar; 赠送原API文档:httpclient-4.5.13-javadoc.jar; 赠送源代码:httpclient-4.5.13-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.13.pom; 包含翻译后的API文档:...
httpclient jar包 httpclient jar包 httpclient jar包
赠送jar包:httpclient-4.5.5.jar; 赠送原API文档:httpclient-4.5.5-javadoc.jar; 赠送源代码:httpclient-4.5.5-sources.jar; 包含翻译后的API文档:httpclient-4.5.5-javadoc-API文档-中文(简体)版.zip ...
帮助程序员快速从Apache的HttpClient 3.x升级到HttpClient 4.x
赠送jar包:httpclient-4.5.13.jar; 赠送原API文档:httpclient-4.5.13-javadoc.jar; 赠送源代码:httpclient-4.5.13-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.13.pom; 包含翻译后的API文档:...
httpClient4.3.6 HttpClient使用详解 httpClient中文帮助文档
HttpClient jar包
httpClientUtil工具类