1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class NetUtil {
private static String[] agents={
"Mozilla/4.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.",
"Microsoft Internet Explorer/5.",
"Microsoft Internet Explorer/6.",
"Microsoft Internet Explorer/7."
};
public static BufferedReader openBufferedReader(String urlStr) throws Exception{
return new BufferedReader(new InputStreamReader(openConnection(urlStr).getInputStream()));
}
public static URLConnection openConnection(String urlStr) throws Exception{
URLConnection uc;
URL url=new URL(urlStr);
uc=url.openConnection();
uc.setDefaultUseCaches(false);
uc.setUseCaches(false);
uc.setRequestProperty("Cache-Control", "max-age=0,no-cache");
uc.setRequestProperty("User-Agent",agents[(int)(Math.random()*agents.length)]+Math.random()*10);
uc.setRequestProperty("Pragma", "no-cache");
return uc;
}
public static void openWebExplorer(String url){
try{
Runtime.getRuntime().exec("explorer "+url);
}catch(Exception ex){
Yog.getInstance().excep(NetUtil.class,ex);
}
}
} |