java伪装referer

注:需要引包!


HttpClient http = new HttpClient();    

GetMethod get = new GetMethod("http://192.168.0.75:8001/login/test.jsp");//访问的地址  
try{  
get.addRequestHeader("accept-encoding", "gzip,deflate"); //支持gzip  
get.addRequestHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Alexa Toolbar; Maxthon 2.0)"); //模拟浏览器  
get.addRequestHeader("referer","www.baidu.com");//伪装的地址  
int er = http.executeMethod(get);  
if(er==200){
System.out.println(get.getResponseContentLength());  
String html = get.getResponseBodyAsString();  
System.out.println(html);                   //页面代码  
System.out.println(html.getBytes().length); //输出文件的长度  
}
}catch(Exception e){}
finally{  
get.releaseConnection();  
}

你可能感兴趣的:(java伪装referer)