调用第三方的webService接口,发送短信

简单的测试 调用第三方的webService 接口 ,记录一下web

public class TestDemo {    public static void main(String[] args) throws Exception {        Long timeStamp=new Date().getTime();        String message="11";        //服务的地址        URL wsUrl = new URL("http://127.0.0.1:9181/SendSmsService");        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 ="<?xml version =\"1.0\" encoding=\"UTF-8\"?>\n" +                "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v3=\"http://www.csapi.org/schema/parlayx/common/v3_1\" xmlns:loc=\"http://www.csapi.org/schema/parlayx/sms/send/v3_1/local\">\n" +                "  <soapenv:Header>\n" +                "   <v3:RequestSOAPHeader>\n" +                "    <spId>17</spId>\n" +                "    <spPassword>e10adc3949ba59abbe56e057f20f883e</spPassword>\n" +                "    <timeStamp>timeStamp</timeStamp>\n" +                "    <serviceId>27</serviceId>\n" +                "   </v3:RequestSOAPHeader>\n" +                "  </soapenv:Header>\n" +                " <soapenv:Body>\n" +                "  <loc:sendSms>\n" +                "    <loc:addresses>86187123456</loc:addresses>\n" +                "\t<loc:senderName>852574900001</loc:senderName>\n" +                "    <loc:message>\n" +                "\t<![CDATA[TEST 60 2018年12月19日10:01:12]]>\n" +                "</loc:message>\n" +                "    <loc:receiptRequest>\n" +                "     <endpoint></endpoint>\n" +                "     <interfaceName>sendSms</interfaceName>\n" +                "     <correlator>123</correlator>\n" +                "    </loc:receiptRequest>\n" +                "  </loc:sendSms>\n" +                " </soapenv:Body>\n" +                "</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);        System.out.println("发送成功!");//        String [] arr={};//        arr= s.split("<sms1:result>");//        String [] arr1={};//        arr1=arr[1].split("</sms1:result>");//        System.out.println(arr1[0]);//        String ss=arr[0];////        URL wsUrl1 = new URL("http://127.0.0.1:9181/getSmsDeliveryStatus");//        HttpURLConnection conn1 = (HttpURLConnection) wsUrl1.openConnection();////        conn1.setDoInput(true);//        conn1.setDoOutput(true);//        conn1.setRequestMethod("POST");//        conn1.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");//        OutputStream os1 = conn1.getOutputStream();////        String soap1 ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +//                "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\n" +//                "\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\n" +//                "\" xmlns:comm3=\"http://www.csapi.org/schema/parlayx/common/v3_1\" xmlns:sms1=\"http://www.csapi.org/schema/parlayx/sms/send/v3_1/local\">\n" +//                "    <SOAP-ENV:Header></SOAP-ENV:Header>\n" +//                "    <SOAP-ENV:Body SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +//                "        <sms1:sendSmsResponse>\n" +//                "            <sms1:result>"+ss+"</sms1:result>\n" +//                "        </sms1:sendSmsResponse>\n" +//                "    </SOAP-ENV:Body>\n" +//                "</SOAP-ENV:Envelope>";//        os1.write(soap1.getBytes());////        InputStream is1 = conn.getInputStream();//        byte[] b1 = new byte[1024];//        int len1 = 0;//        String s1 = "";//        while((len = is1.read(b1)) != -1){//            String ss1 = new String(b1,0,len1,"UTF-8");//            s1 += ss1;//        }//        System.out.println(s1);//        System.out.println("接受成功");        is.close();        os.close();        conn.disconnect();    }}