/* * 通过HTTP访问接口, * 详情,返回一个Map对象 */public static MapcallByHTTP(String URL,String data,String RequestMethod,boolean encrypt) throws Exception{ StringBuffer returnData=new StringBuffer(); InputStream in = null; //网络连接 logger.info("url:url:"+URL); try { URL url = new URL(URL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod(RequestMethod); conn.setRequestProperty("Cache-Control", "no-cache"); conn.setRequestProperty("Charsert", "UTF-8"); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.connect(); if(data!=null&&!data.equals("")){ OutputStream outputStream = conn.getOutputStream(); outputStream.write(data.getBytes("UTF-8")); outputStream.flush(); outputStream.close(); } in = conn.getInputStream(); } catch (Exception e) { e.printStackTrace(); logger.error("接口连接超时!"); } //解析数据 try{ if (in != null) { BufferedReader bufferIn = new BufferedReader(new InputStreamReader(in,"UTF-8")); String temp=null; while((temp=bufferIn.readLine())!=null){ returnData.append(temp); } bufferIn.close(); in.close(); if (encrypt) { logger.info(returnData.toString()); return (Map )JSON.parse(DesEncrypt.getInstance().decrypt(returnData.toString())); } else { logger.info(returnData.toString()); return (Map )JSON.parse(returnData.toString()); } } } catch (ApplicationException e) { e.printStackTrace(); logger.error("系统接口运行失败!"); throw new ApplicationException(); } logger.error("系统接口连接失败!"); return null; }