package com.itcast.refer;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.servlet.http.HttpServlet;
public class Client extends HttpServlet {
/*
* 一般,别人比较有特色的网站,都不用许你盗链 所谓盗链就是在别的地方直接访问到特色网站的资源
*
* 首先用httpwatch获得别人的头字段referer的值 然后把值设置进你的链接,实现带链接的访问
*/
public static void main(String[] args) throws Exception {
URL uri = new URL("http://localhost/day4/refer.html");
URLConnection conn = uri.openConnection();
conn.addRequestProperty("referer", "http://localhost/day4/refer.html");// 把防盗链设置进你自己的URL
InputStream in = conn.getInputStream();
InputStream fs = in;
byte[] b = new byte[1024];
while ((fs.read(b)) != -1) {
System.out.println(new String(b, 0, b.length));
}
in.close();
fs.close();
}
}