使用Jsoup加代理发送get请求
其他
2018-09-28 23:45:14
阅读次数: 0
- public static String get(String uri){
-
-
- System.setProperty("https.proxySet", "true");
- System.getProperties().put("https.proxyHost", ip);
- System.getProperties().put("https.proxyPort", port);
-
-
- Document doc = null;
- String agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)"
- + " Chrome/56.0.2924.87 Safari/537.36" ;
- try {
- doc = Jsoup.connect(uri).ignoreContentType(true)
- .userAgent(agent)
-
-
- .ignoreHttpErrors(true)
- .timeout(3000).get();
- } catch (IOException e) {
- System.out.println(e.getMessage()+" **************** get");
- }
- if (doc!=null) {
- return doc.body().text();
- }
- return null;
- }
- public static String get(String uri){
-
-
- System.setProperty("https.proxySet", "true");
- System.getProperties().put("https.proxyHost", ip);
- System.getProperties().put("https.proxyPort", port);
-
-
- Document doc = null;
- String agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)"
- + " Chrome/56.0.2924.87 Safari/537.36" ;
- try {
- doc = Jsoup.connect(uri).ignoreContentType(true)
- .userAgent(agent)
-
-
- .ignoreHttpErrors(true)
- .timeout(3000).get();
- } catch (IOException e) {
- System.out.println(e.getMessage()+" **************** get");
- }
- if (doc!=null) {
- return doc.body().text();
- }
- return null;
- }
转载自blog.csdn.net/hephec/article/details/79259301