朱杰兵blog

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

          通過 URL Connection 方式調用

          Posted on 2016-04-25 17:14 朱杰兵 閱讀(121) 評論(0)  編輯  收藏
          http://www.cnblogs.com/siqi/p/3475222.html
          import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; /**  * 通過UrlConnection調用Webservice服務  *  */ public class App {      public static void main(String[] args) throws Exception {         //服務的地址         URL wsUrl = new URL("http://192.168.1.100:6789/hello");                  HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();                  conn.setDoInput(true);         conn.setDoOutput(true);         conn.setRequestMethod("POST");         conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");                  OutputStream os = conn.getOutputStream();                  //請求體         String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:q0=\"http://ws.itcast.cn/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +                        "<soapenv:Body> <q0:sayHello><arg0>aaa</arg0>  </q0:sayHello> </soapenv:Body> </soapenv:Envelope>";                  os.write(soap.getBytes());                  InputStream is = conn.getInputStream();                  byte[] b = new byte[1024];         int len = 0;         String s = "";         while((len = is.read(b)) != -1){             String ss = new String(b,0,len,"UTF-8");             s += ss;         }         System.out.println(s);                  is.close();         os.close();         conn.disconnect();     } }

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


          網站導航:
           
          主站蜘蛛池模板: 正阳县| 临颍县| 洮南市| 安顺市| 扶绥县| 宣武区| 伊金霍洛旗| 阿坝县| 垣曲县| 武宁县| 乐清市| 福建省| 商都县| 邢台县| 长子县| 炉霍县| 焦作市| 松原市| 贵德县| 濮阳市| 浮梁县| 同仁县| 中山市| 丽水市| 河北省| 巩义市| 乌苏市| 永春县| 岐山县| 荥阳市| 祥云县| 温泉县| 河南省| 绥德县| 中西区| 舒兰市| 水富县| 广汉市| 万山特区| 丰镇市| 东阳市|