public static String jsoupEntity(String url1) {
InputStream is = null;
BufferedReader buffer = null;
try {
String[] ips = newIp();//获取自定义ip 127.0.0.1:80 split
if (null == ips) return null;
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ips[0], Integer.parseInt(ips[1])));
URL url = new URL(url1);
if (url1.startsWith("https")) {
HttpsURLConnection urlcon = (HttpsURLConnection) url.openConnection(proxy);
urlcon.setRequestMethod("GET");
urlcon.setConnectTimeout(1000);
urlcon.connect();
is = urlcon.getInputStream();
} else {
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(proxy);
urlcon.setRequestMethod("GET");
urlcon.setConnectTimeout(1000);
urlcon.connect();
is = urlcon.getInputStream();
}
buffer = new BufferedReader(new InputStreamReader(is));
String bs = buffer.lines().collect(Collectors.joining());
return bs;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (buffer != null) {
buffer.close();
}
if (is != null) {
is.close();
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
用自定义ip获取url数据
猜你喜欢
转载自blog.csdn.net/wangh92/article/details/90601970
今日推荐
周排行