dimi360
dimi360
2016-05-14 07:46
采纳率: 100%
浏览 1.7k
已采纳

求解读这段代码是什么意思

public static String conSvr() {
(URL)null;
(InputStream)null;
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder.append("ben123.a3w.cn");
try {
StringBuffer stringBuffer = new StringBuffer();
StringBuffer stringBuffer2 = new StringBuffer();
StringBuffer stringBuffer3 = new StringBuffer();
URL uRL = new URL(stringBuffer.append(stringBuffer2.append(stringBuffer3.append("http://").append(stringBuilder.toString()).toString()).append("/").toString()).append(stringBuilder2.toString()).toString());
HttpURLConnection httpURLConnection = (HttpURLConnection)uRL.openConnection();
httpURLConnection.addRequestProperty("Host", stringBuilder.toString());
if (httpURLConnection.getResponseCode() != 200) return null;
InputStream inputStream = httpURLConnection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader((Reader)inputStreamReader);
StringBuilder stringBuilder3 = new StringBuilder();
(String)null;
do {
String string2;
if ((string2 = bufferedReader.readLine()) == null) {
return stringBuilder3.toString();
}
StringBuffer stringBuffer4 = new StringBuffer();
stringBuilder3.append(stringBuffer4.append(string2).append("\n").toString());
} while (true);
}
catch (IOException var9_13) {
return null;
}
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳

    这是反编译的代码,所以变量名丢失了。这段代码视图访问一个网站,返回对应的html

    点赞 评论
  • wojiushiwo945you
    毕小宝 2016-05-15 13:11

    是使用HttpURLConnection 类模拟浏览器请求URL,得到某个网站的源码。

    openConnection();
     InputStream inputStream = httpURLConnection.getInputStream();
     InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    

    第一句就是连接URL地址,后面两句就是获取请求响应的内容。其实这段代码也是java爬虫的底层实现方法的。

    点赞 评论

相关推荐