朱杰兵blog

          jonhney'blog
          posts - 140, comments - 1, trackbacks - 0, articles - 0

          導航

          <2016年4月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜


          package com.what21.service.demo02;
           
          import java.io.BufferedReader;
          import java.io.InputStreamReader;
          import java.io.OutputStream;
          import java.net.HttpURLConnection;
          import java.net.URL;
           
          public class CallByHttp {
           
              private static String actionBySOAP(){
                  StringBuilder sb = new StringBuilder();
                  sb.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas" +
                          ".xmlsoap.org/soap/envelope/\" xmlns:sms=\"helloworld\">");
                  sb.append("<soapenv:Header/>");
                  sb.append("<soapenv:Body>");
                  sb.append("<sms:sendSMS>");
                  sb.append("<sms:in0>123</sms:in0>");
                  sb.append("</sms:sendSMS>");
                  sb.append("</soapenv:Body>");
                  sb.append("</soapenv:Envelope>");
                  return sb.toString();
              }
            
              private static String callWebService(String wsdl)
                      throws Exception{
                  System.setProperty("sun.net.client.defaultConnectTimeout","20000");
                  System.setProperty("sun.net.client.defaultReadTimeout","20000");
                   
                  // URL連接
                  URL url = new URL(wsdl);
                  HttpURLConnection conn = (HttpURLConnection)url.openConnection();
                  // conn.setRequestMethod("GET");
                  conn.setRequestMethod("POST");
                  conn.setRequestProperty("Content-Length", String.valueOf(actionBySOAP().getBytes().length));
                  conn.setRequestProperty("Content-Type","text/xml; charset=GBK");
                  conn.setDoOutput(true);
                  conn.setDoInput(true);
                  conn.setConnectTimeout(20000);
                  // 請求輸入內容
                  OutputStream output = conn.getOutputStream();
                  output.write(actionBySOAP().getBytes());
                  output.flush();
                  output.close();
                  // 請求返回內容
                  InputStreamReader isr = new InputStreamReader(conn.getInputStream());
                  BufferedReader br = new BufferedReader(isr);
                  StringBuilder sb = new StringBuilder();
                  String str = null;
                  while((str = br.readLine())!=null){
                      sb.append(str + "\n");
                  }
                  br.close();
                  isr.close();
                  return sb.toString();
              }
            
            
              /**
              * @param args
              */
              public static void main(String[] args) throws Exception {
                  String result = callWebService(WSDL);
                  System.out.println(result);
              }
           
          }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 大名县| 突泉县| 拉萨市| 双城市| 乐安县| 柞水县| 固原市| 新民市| 桐乡市| 南江县| 玉环县| 咸丰县| 黄龙县| 西丰县| 潼南县| 湛江市| 贵定县| 防城港市| 大渡口区| 麻城市| 福安市| 聊城市| 固镇县| 青海省| 高淳县| 宽甸| 利川市| 河北省| 宁远县| 隆化县| 盐亭县| 夏河县| 固阳县| 博湖县| 定襄县| 商水县| 盐亭县| 普格县| 大厂| 鸡西市| 仙居县|