1.工具类里静态方法
public static String request( String httpArg) { String httpUrl="http://tool.bitefu.net/jiari/"; BufferedReader reader = null; String result = null; StringBuffer sbf = new StringBuffer(); httpUrl = httpUrl + "?d=" + httpArg; try { URL url = new URL(httpUrl); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream is = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String strRead = null; while ((strRead = reader.readLine()) != null) { sbf.append(strRead); sbf.append("\r\n"); } reader.close(); result = sbf.toString(); //Map map= (Map) JSON.parse(result); //String res=(String)map.get(httpArg); } catch (Exception e) { e.printStackTrace(); } return result; }
2.主类里使用
//判断今天是否是工作日 周末 还是节假日 SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd"); String httpArg=f.format(new Date()); System.out.println(httpArg); String jsonResult = HolidayUtils.request(httpArg); System.out.println(jsonResult);
//0 上班 1周末 2节假日