今天网上莫名其妙naichabiao.com和京东就联系上了,进入naichabiao.com直接就跳到了京东的主页上去了,是怎么实现的呢?
其实很简单的啦。首先看怎么趴下来网页的代码。
下面是实现的java代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLConnection;
public class getUrl {
public static void main(String[] args) throws IOException {
java.net.URL url=new java.net.URL("http://naichabiao.com");
URLConnection con=url.openConnection();
BufferedReader bf=new BufferedReader(new InputStreamReader(con.getInputStream()));
String line=null;
while((line=bf.readLine())!=null){
System.out.println(line);
}
}
}
然后就可以发现他的代码其实就是:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
location.replace("http://www.taobao.com")
</script>
</head>
<body>
</body>
</html>
额。。。扒下来才发现好无趣。。。,重点是我们怎么扒代码啦