e9f774c12a775364a71fbc0f0b42024442f3543e.svn-base 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package UIJ.UIJ03;
  2. import org.apache.soap.util.xml.*;
  3. import org.apache.soap.*;
  4. import org.apache.soap.rpc.*;
  5. import java.io.*;
  6. import java.net.*;
  7. import java.util.Vector;
  8. public class UIJ030052 {
  9. public static String sendPost(String url, String param) {
  10. UIJ030054 httpsUrlConnectionMessageSender = new UIJ030054();
  11. HttpURLConnection conn;
  12. PrintWriter out = null;
  13. BufferedReader in = null;
  14. String result = "";
  15. try {
  16. // URL realUrl = new URL(url);
  17. // 打开和URL之间的连接
  18. conn = httpsUrlConnectionMessageSender.createConnection(new URI(url ));
  19. // 设置通用的请求属性
  20. conn.setRequestProperty("accept", "*/*");
  21. conn.setRequestProperty("connection", "Keep-Alive");
  22. conn.setRequestProperty("user-agent",
  23. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  24. // 发送POST请求必须设置如下两行
  25. conn.setDoOutput(true);
  26. conn.setDoInput(true);
  27. // 定义BufferedReader输入流来读取URL的响应
  28. in = new BufferedReader(
  29. new InputStreamReader(conn.getInputStream(),"UTF-8"));
  30. String line;
  31. while ((line = in.readLine()) != null) {
  32. result += line;
  33. }
  34. }
  35. catch (Exception e) {
  36. System.out.println("发送 POST 请求出现异常!"+e);
  37. e.printStackTrace();
  38. }
  39. //使用finally块来关闭输出流、输入流
  40. finally{
  41. try{
  42. if(out!=null){
  43. out.close();
  44. }
  45. if(in!=null){
  46. in.close();
  47. }
  48. }
  49. catch(IOException ex){
  50. ex.printStackTrace();
  51. }
  52. }
  53. return result;
  54. }
  55. public static String jsonPost(String url, String param) {
  56. PrintWriter out = null;
  57. BufferedReader in = null;
  58. String result = "";
  59. try {
  60. URL realUrl = new URL(url);
  61. // 打开和URL之间的连接
  62. URLConnection conn = realUrl.openConnection();
  63. // 设置通用的请求属性
  64. conn.setRequestProperty("accept", "*/*");
  65. conn.setRequestProperty("connection", "Keep-Alive");
  66. conn.setRequestProperty("user-agent",
  67. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  68. // 发送POST请求必须设置如下两行
  69. conn.setDoOutput(true);
  70. conn.setDoInput(true);
  71. // 定义BufferedReader输入流来读取URL的响应
  72. in = new BufferedReader(
  73. new InputStreamReader(conn.getInputStream(),"UTF-8"));
  74. String line;
  75. while ((line = in.readLine()) != null) {
  76. result += line;
  77. }
  78. } catch (Exception e) {
  79. System.out.println("发送 POST 请求出现异常!"+e);
  80. e.printStackTrace();
  81. }
  82. //使用finally块来关闭输出流、输入流
  83. finally{
  84. try{
  85. if(out!=null){
  86. out.close();
  87. }
  88. if(in!=null){
  89. in.close();
  90. }
  91. }
  92. catch(IOException ex){
  93. ex.printStackTrace();
  94. }
  95. }
  96. return result;
  97. }
  98. }