读书人

用http跟URLconnection盗链

发布时间: 2012-12-24 10:43:13 作者: rapoo

用http和URLconnection盗链

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();

}

}


读书人网 >编程

热点推荐