a9d87954de121da9719a54627f7089b9257d2f2f.svn-base 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package xin.glue.user.common;
  2. /*
  3. import org.apache.soap.util.xml.*;
  4. import org.apache.soap.*;
  5. import org.apache.soap.rpc.*;
  6. */
  7. import java.io.*;
  8. import java.net.*;
  9. import java.util.Vector;
  10. public class UIJ030052 {
  11. public static String sendPost(String url, String param) {
  12. UIJ030054 httpsUrlConnectionMessageSender = new UIJ030054();
  13. HttpURLConnection conn;
  14. PrintWriter out = null;
  15. BufferedReader in = null;
  16. String result = "";
  17. /*try {
  18. java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) new URL(url)
  19. .openConnection();
  20. httpConn.setDoOutput(true);
  21. httpConn.setDoInput(true);
  22. OutputStream outStream = httpConn.getOutputStream();
  23. OutputStreamWriter outBuf = new OutputStreamWriter(outStream);
  24. //outBuf.write("{\"memo0\":\"子版号\",\"startTime\":\"2018-02-01 00:00:00\",\"endTime\":\"2018-08-31 23:59:59\"}");//参数
  25. outBuf.flush();
  26. outBuf.close();
  27. outStream.close();
  28. // get result
  29. InputStream inStream = httpConn.getInputStream();
  30. if (inStream != null) {
  31. InputStreamReader readStream = new InputStreamReader(inStream);
  32. int c;
  33. while ((c = readStream.read()) != -1) {
  34. result = result + ((char) c);
  35. }
  36. // close stream
  37. inStream.close();
  38. readStream.close();
  39. }
  40. System.out.println(result);
  41. } */
  42. try {
  43. // URL realUrl = new URL(url);
  44. // 打开和URL之间的连接
  45. conn = httpsUrlConnectionMessageSender.createConnection(new URI(url ));
  46. // 设置通用的请求属性
  47. conn.setRequestProperty("accept", "*/*");
  48. conn.setRequestProperty("connection", "Keep-Alive");
  49. conn.setRequestProperty("user-agent",
  50. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  51. // 发送POST请求必须设置如下两行
  52. conn.setDoOutput(true);
  53. conn.setDoInput(true);
  54. // 定义BufferedReader输入流来读取URL的响应
  55. in = new BufferedReader(
  56. new InputStreamReader(conn.getInputStream(),"UTF-8"));
  57. String line;
  58. while ((line = in.readLine()) != null) {
  59. result += line;
  60. }
  61. }
  62. catch (Exception e) {
  63. System.out.println("发送 POST 请求出现异常!"+e);
  64. e.printStackTrace();
  65. }
  66. //使用finally块来关闭输出流、输入流
  67. finally{
  68. try{
  69. if(out!=null){
  70. out.close();
  71. }
  72. if(in!=null){
  73. in.close();
  74. }
  75. }
  76. catch(IOException ex){
  77. ex.printStackTrace();
  78. }
  79. }
  80. return result;
  81. }
  82. public static String jsonPost(String url, String param) {
  83. PrintWriter out = null;
  84. BufferedReader in = null;
  85. String result = "";
  86. try {
  87. URL realUrl = new URL(url);
  88. // 打开和URL之间的连接
  89. URLConnection conn = realUrl.openConnection();
  90. // 设置通用的请求属性
  91. conn.setRequestProperty("accept", "*/*");
  92. conn.setRequestProperty("connection", "Keep-Alive");
  93. conn.setRequestProperty("user-agent",
  94. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  95. // 发送POST请求必须设置如下两行
  96. conn.setDoOutput(true);
  97. conn.setDoInput(true);
  98. // 定义BufferedReader输入流来读取URL的响应
  99. in = new BufferedReader(
  100. new InputStreamReader(conn.getInputStream(),"UTF-8"));
  101. String line;
  102. while ((line = in.readLine()) != null) {
  103. result += line;
  104. }
  105. } catch (Exception e) {
  106. System.out.println("发送 POST 请求出现异常!"+e);
  107. e.printStackTrace();
  108. }
  109. //使用finally块来关闭输出流、输入流
  110. finally{
  111. try{
  112. if(out!=null){
  113. out.close();
  114. }
  115. if(in!=null){
  116. in.close();
  117. }
  118. }
  119. catch(IOException ex){
  120. ex.printStackTrace();
  121. }
  122. }
  123. return result;
  124. }
  125. }