public static void testHttpQuest() { // {‘pfxInfo‘:‘no‘,‘isPfx‘:‘no‘,‘signInfo‘:‘中文‘,‘passCode‘:‘‘,‘signType‘:‘yes‘} logger.info("开始下载更新CRL"); // 创建URL 对象 URL url = null; byte[] b = null; FileOutputStream fos = null; InputStream is = null; HttpURLConnection httpUrlConnection = null; try { url = new URL("http://101.201.80.221:8899/VerifyInfoService/doSign"); // url = new URL("http://localhost:8888//VerifyInfoService/doSign"); // 获取 httpUrl连接 httpUrlConnection = (HttpURLConnection) url.openConnection(); httpUrlConnection.setRequestMethod("POST"); httpUrlConnection.setDoInput(true); httpUrlConnection.setDoOutput(true); String params = "signedInfoValue={‘pfxInfo‘:‘no‘,‘isPfx‘:‘no‘,‘signInfo‘:‘中文‘,‘passCode‘:‘‘,‘signType‘:‘yes‘}"; httpUrlConnection.setRequestProperty("accept", "*/*"); httpUrlConnection.setRequestProperty("connection", "Keep-Alive"); httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpUrlConnection.connect(); OutputStreamWriter outStream = new OutputStreamWriter( httpUrlConnection.getOutputStream(), "UTF-8"); outStream.write(params); outStream.flush(); outStream.close(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( httpUrlConnection.getInputStream())); String line; StringBuffer responseResult = new StringBuffer(); while ((line = bufferedReader.readLine()) != null) { responseResult.append(line); } System.out.println(responseResult.toString()); int responseCode = httpUrlConnection.getResponseCode(); System.out.println(responseCode); httpUrlConnection.disconnect(); } catch (MalformedURLException e) { logger.info("下载CRL列表失败!"); e.printStackTrace(); } catch (IOException e) { logger.info("下载CRL列表失败!"); e.printStackTrace(); } }
时间: 2024-11-08 15:34:58