朱杰兵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();     } }

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 蓬溪县| 依安县| 玉屏| 连江县| 苏尼特左旗| 泰安市| 普陀区| 伊金霍洛旗| 图片| 波密县| 桓仁| 斗六市| 巴青县| 石泉县| 历史| 宁国市| 丽江市| 德格县| 永登县| 深州市| 泸定县| 东山县| 栖霞市| 桐乡市| 伊宁市| 尤溪县| 阿克| 内丘县| 湘乡市| 金秀| 美姑县| 尖扎县| 遂川县| 同心县| 阿拉善右旗| 鹤庆县| 新津县| 清水河县| 鹤岗市| 榆林市| 罗定市|