标签:block 发送请求 gre 可变 使用 ringbuf input reader 缓冲区
加密前:{"time":"1510053168455","username":"GH_DATA_EXCHANGE","password":"15E45RRM"} 加密后:eyJ0aW1lIjoiMTUxMDA1MzE2ODQ1NSIsInVzZXJuYW1lIjoiR0hfREFUQV9FWENIQU5HRSIsInBh c3N3b3JkIjoiMTVFNDVSUk0ifQ== %7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E7%99%BB%E5%BD%95%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%220ef9e732-008d-4875-a8d2-60abde59ba60%22%7D {"r_code":"200","r_msg":"登录成功","count":0,"data":"0ef9e732-008d-4875-a8d2-60abde59ba60"} 转码前:%7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E7%99%BB%E5%BD%95%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%220ef9e732-008d-4875-a8d2-60abde59ba60%22%7D 转码后:{"r_code":"200","r_msg":"登录成功","count":0,"data":"0ef9e732-008d-4875-a8d2-60abde59ba60"} data<--->0ef9e732-008d-4875-a8d2-60abde59ba60 %7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E6%93%8D%E4%BD%9C%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%5B%5D%7D {"r_code":"200","r_msg":"操作成功","count":0,"data":[]} 转码前:%7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E6%93%8D%E4%BD%9C%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%5B%5D%7D 转码后:{"r_code":"200","r_msg":"操作成功","count":0,"data":[]} {"r_code":"200","r_msg":"操作成功","count":0,"data":[]}
package queryExpireList; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; //import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import com.rl.client1.TestLogin2Action; import net.sf.json.JSONException; import net.sf.json.JSONObject; //import org.json.JSONException; //import org.json.JSONObject; import test.BASE64; public class QueryExpireList { public static String query(String username,String password){ //定义WebService的URL //URL url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login2.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login.action"); URL url; PrintWriter ptout = null; InputStream in = null; StringBuffer sb = null; String apptoken = null; try { //url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login2.action"); //url = new URL("http://10.168.41.107:8080/fsWebServiceWebHall/business/login2.action"); url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/queryExpireList.action"); //打开连接获得URLConnection HttpURLConnection uc = (HttpURLConnection)url.openConnection(); //打开输入输出的开关 uc.setDoInput(true); uc.setDoOutput(true);//开启输入输出 //设置Connection uc.setRequestProperty("connection", "Keep-Alive"); //设置Accept uc.setRequestProperty("accept", "*/*"); uc.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); //组装消息体 apptoken = TestLogin2Action.getLogin(username, password); //根据HttpURLConnection获得输出流 OutputStream out = uc.getOutputStream(); // 获取URLConnection对象对应的输出流 ptout = new PrintWriter(out); // 发送请求参数 //ptout.print("appkey="+appkey); ptout.print("apptoken="+apptoken); // flush输出流的缓冲 ptout.flush(); //out.write(encodeappkey.getBytes()); //int httpCode = httpuc.getResponseCode(); //System.out.println(httpCode); //如果请求成功 //if(httpuc.getResponseCode()==200){ //获得输入流 in = uc.getInputStream();//通过输入流把消息接收完 //使用输入缓冲区 BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8")); //写Socket的那种输入流的方式来读它 String line = null; //读取响应的消息 sb = new StringBuffer(); while((line = br.readLine())!=null ){ sb.append(line); } }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally{ try{ if(ptout!=null){ ptout.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } String decodesb = ""; System.out.println(sb.toString()); try { decodesb = java.net.URLDecoder.decode(sb.toString(),"UTF-8"); System.out.println(decodesb); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("转码前:"+sb); System.out.println("转码后:" + decodesb); /*// 创建JSON解析对象(两条规则的体现:大括号用JSONObject,注意传入数据对象) JSONObject obj; String data = null; try { //obj = new JSONObject(decodesb); obj = JSONObject.fromObject(decodesb); //obj.后面有各种数据类型,根据对象来选择使用的数据类型 data = obj.getString("data"); // 同理如上,这里的age为Int类型,我们就用对应的类型进行解析 //int age = obj.getInt("age"); // 最后输出到控制台 System.out.println("data"+"<--->"+data); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ return decodesb; } public static void main(String[] args){ //String queryExpireList = QueryExpireList.query("0216", "1234"); //String apptoken = TestLogin2Action.getLogin("GH_DATA_EXCHANGE","15E45RRM"); String queryExpireList = QueryExpireList.query("GH_DATA_EXCHANGE", "15E45RRM"); System.out.println(queryExpireList); } public static void main1(String[] args){ //定义WebService的URL //URL url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login2.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login.action"); URL url; PrintWriter ptout = null; InputStream in = null; StringBuffer sb = null; try { //url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login2.action"); url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/queryExpireList.action"); //打开连接获得URLConnection URLConnection uc = url.openConnection(); //强转成HttpURLConnection //HttpURLConnection httpuc = (HttpURLConnection) uc; //打开输入输出的开关 uc.setDoInput(true); uc.setDoOutput(true);//开启输入输出 //设置请求方式 //uc.setRequestMethod("POST"); //设置Connection uc.setRequestProperty("connection", "Keep-Alive"); //设置Charset //httpuc.setRequestProperty("Charset", "UTF-8"); //设置Accept //httpuc.setRequestProperty("Accept", "application/json"); uc.setRequestProperty("accept", "*/*"); //设置content-type //httpuc.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); //httpuc.setRequestProperty("Content-Type", "text/html"); uc.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); //组装消息体 //String data = "c1f2e41650919327d85367194f75d4cf6a5f39dcef42ae6a3c33015ca92935009d6c6c4ed59a67637d54f29f7e77b9e2af95afddd4dc77b28a3d1d5056a52fe11ea6f735f35d8b62b3c2ebd9d43e533d"; /* Date date = new Date(); DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //DateFormat dateTimeformat = new SimpleDateFormat("yyyyMMddHHmmss"); String strBeginDate = dateTimeformat.format(date); System.out.println(date); System.out.println(strBeginDate); String appkey = "02161234"+date; appkey = "02241234"+strBeginDate; String data = java.net.URLEncoder.encode(appkey, "utf-8"); System.out.println("编码后:" + data);//加密后 */ String username = "GH_DATA_EXCHANGE"; // 用户账号 String password = "15E45RRM"; // 密码 long time = System.currentTimeMillis(); // 当前时间,毫秒 //String str="{\"username\":"+ username +",\"password\":"+ password +",\"time\": "+ time +"}"; // 原数据 //String str="{\"username\":"+ username +",\"password\":"+ password +",\"time\":"+ time +"}"; // 原数据 //String str="{\"time\":"+ time +",\"username\":"+ username +",\"password\":"+ password +"}"; // 原数据 String str = "{\"time\":\""+time+"\",\"username\":\""+username+"\",\"password\":\""+password+"\"}"; // 原数据 //String str = username+password+time; //String appkey = AES.method1(str); System.out.println("加密前:"+str); //SymmetricEncoder se=new SymmetricEncoder(); //String appkey = se.AESEncode("使用AES对称加密", str); //System.out.println("根据输入的规则"+"使用AES对称加密"+"加密后的密文是:"+se.AESEncode("使用AES对称加密", str)); //System.out.println("根据输入的规则"+"使用AES对称解密"+"解密后的明文是:"+se.AESDncode("使用AES对称解密",se.AESEncode("使用AES对称加密", str))); //System.out.println("根据输入的规则"+"使用AES对称解密"+"解密后的明文是:"+se.AESDncode("使用AES对称解密",appkey)); //System.out.println("加密后:" + appkey); // 加密后 //appkey = "fB75+Z+CXIuVwqDNJYbKzZmHuVGORfL9TxqEx5AXE5w="; // String encode = java.net.URLEncoder.encode(str,"utf-8"); // System.out.println("编码后:" + encode); String appkey = BASE64.encryptBASE64(str.toString().getBytes()); //String appkey = new sun.misc.BASE64Encoder().encode(str.toString().getBytes()); // String appkey = BASE64.encryptBASE64(encode.getBytes()); //appkey = "eyJ1c2VybmFtZSI6Imd6OTkiLCJwYXNzd29yZCI6IjEyMzQiLCJ0aW1lIjogMTQ0ODQzMjY3NTE5NH0="; //appkey = "c1f2e41650919327d85367194f75d4cf6a5f39dcef42ae6a3c33015ca92935009d6c6c4ed59a67637d54f29f7e77b9e2af95afddd4dc77b28a3d1d5056a52fe11ea6f735f35d8b62b3c2ebd9d43e533d"; System.out.println("加密后:"+appkey); //String data = "eyJ1c2VybmFtZSI6Imd6OTkiLCJwYXNzd29yZCI6IjEyMzQiLCJ0aW1lIjogMTQ0ODQzMjY3NTE5NH0="; /* Date date = new Date(); String appkey = "02241234"+date; String data = java.net.URLEncoder.encode(appkey, "utf-8"); System.out.println("编码后:" + data);//加密后 */ //根据HttpURLConnection获得输出流 OutputStream out = uc.getOutputStream(); //用输出流把消息发送到服务端 //out.write(data.getBytes());//已经把消息给写过去了. //System.out.println(appkey.getBytes()); //String encodeappkey = java.net.URLEncoder.encode(appkey,"utf-8"); //out.write(appkey.getBytes());//已经把消息给写过去了. // 获取URLConnection对象对应的输出流 ptout = new PrintWriter(out); // 发送请求参数 ptout.print("appkey="+appkey); // flush输出流的缓冲 ptout.flush(); //out.write(encodeappkey.getBytes()); //int httpCode = httpuc.getResponseCode(); //System.out.println(httpCode); //如果请求成功 //if(httpuc.getResponseCode()==200){ //获得输入流 in = uc.getInputStream();//通过输入流把消息接收完 //使用输入缓冲区 BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8")); //写Socket的那种输入流的方式来读它 String line = null; //读取响应的消息 sb = new StringBuffer(); while((line = br.readLine())!=null ){ sb.append(line); } }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally{ try{ if(ptout!=null){ ptout.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } String decodesb = null; try { decodesb = java.net.URLDecoder.decode(sb.toString(),"UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("转码前:"+sb); System.out.println("转码后:" + decodesb); // 创建JSON解析对象(两条规则的体现:大括号用JSONObject,注意传入数据对象) JSONObject obj; try { //obj = new JSONObject(decodesb); obj = JSONObject.fromObject(decodesb); //obj.后面有各种数据类型,根据对象来选择使用的数据类型 String data = obj.getString("data"); // 同理如上,这里的age为Int类型,我们就用对应的类型进行解析 //int age = obj.getInt("age"); // 最后输出到控制台 System.out.println("data"+"<--->"+data); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } //StringBuffer是一个可变字符串,我们要把它变成一个文档来解析 //java代码里面解析XML //解析消息,定义读取器对象SAXReader /*SAXReader reader = new SAXReader(); //获得文档对象 Document doc = reader.read(new StringReader(sb.toString()));//它的返回值是一个文档对象Document //使用XPath的方式获得到return这个元素的集合 List<Element> eList = doc.selectNodes("//return"); //遍历元素集合 for (Element element : eList) { System.out.println(element.getText()); }*/ } } //}
南海区行政审批管理系统接口规范v0.3(规划)4.2.【queryExpireList】当天到期业务查询
标签:block 发送请求 gre 可变 使用 ringbuf input reader 缓冲区
原文地址:http://www.cnblogs.com/ZHONGZHENHUA/p/7801022.html