java调用webService接口

来源:互联网 发布:弓箭手升级数据 编辑:程序博客网 时间:2024/05/22 16:38
public static void main(String[] args) throws IOException { URL wsUrl = new URL("http://ne.xxxx.net/services/NE8Service?wsdl");          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:web=\"http://web.operation.ne.xxxx.com/\">"+   "<soapenv:Header/>"+   "<soapenv:Body>"+      "<web:callNE8LogicToString>"+        " <arg0>"+          "<ip>127.0.0.1</ip>" +           "<loginPwd>xxxx</loginPwd>" +            "<loginUser>xxxx</loginUser>" +            "<params>xxxxxx</params>"+            "<scanParams>xxxx</scanParams>"+            "<serverCode>xxxx</serverCode>"+            "<states>xxxx</states>"+         "</arg0>"+      "</web:callNE8LogicToString>"+   "</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();}

原创粉丝点击