"WebService" Debugging method chapter (II)

Source: Internet
Author: User

Before mentioned WebService debugging tools, if you are interested in writing test code, it is very good ah!

I also think so, have the idea to try Oh. Then, my program mainly uses the HttpURLConnection class, first splicing the XML string information that conforms to the SOAP protocol, and then establishes the connection with the WebService server, sends an HTTP request, and prints out after receiving the return information. Process and SoapUI Debugging Tools of the same, the following provides the code of the test program, you can refer to.

Import Java.io.bufferedreader;import Java.io.inputstream;import Java.io.inputstreamreader;import Java.io.outputstream;import Java.net.httpurlconnection;import Java.net.url;public class Http {public String httpGet ( String httpurl) {string reqmsg = "<soapenv:envelope xmlns:soapenv=\" http://www.w3.org/2003/05/soap-envelope\ "> "+" <soapenv:Header> "+" <ns1:username xmlns:ns1=\ "http://service.webservice.ultrapower.com.cn\" soapenv: Mustunderstand=\ "false\" >username</ns1:Username> "+" <ns1:password xmlns:ns1=\ "/http/ Service.webservice.ultrapower.com.cn\ "soapenv:mustunderstand=\" false\ ">userpw</ns1:Password>" + "</ Soapenv:header> "+" <soapenv:Body> "+" <ns1:sendxml xmlns:ns1=\ "/http/ Service.webservice.ultrapower.com.cn\ ">" + "<ns1:requestXml>" + "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>" + "<ReadWhiteList>" + "<srcDeviceType>32</srcDeviceType>" + "<srcDeviceID>321101< /srcdeviceid> "+" <cmd>0</cmd> "+" </ReadWhiteList> "+" </ns1:requestXml> "+" <ns1:busiKey>11</ns1:busiKey> "+" &LT;/NS1: Sendxml> "+" </soapenv:Body> "+" </soapenv:Envelope> "; URL url = null;        HttpURLConnection httpurlconn= null;        StringBuffer datastring = new StringBuffer ("");            String temp = new string (); try{System.out.println (Httpurl);            url = new URL (httpurl);            Httpurlconn= (HttpURLConnection) url.openconnection ();            Httpurlconn.setdooutput (TRUE);            Httpurlconn.setrequestmethod ("POST"); Httpurlconn.setconnecttimeout (300*1000);//300s timeout Httpurlconn.setrequestproperty ("User-agent", "Apache-HttpClient            /4.1.1 (Java 1.5) ");            Httpurlconn.setrequestproperty ("Content-type", "application/soap+xml;charset=utf-8;action=\" urn:SendXML\ "");            OutputStream out = Httpurlconn.getoutputstream ();            Out.write (Reqmsg.tostring (). GetBytes ());            Httpurlconn.connect (); InputStream In =httpurlconn.getinputstream ();            BufferedReader bd = new BufferedReader (new InputStreamReader (in));            while ((Temp=bd.readline ())!=null) {datastring.append (New String (Temp.getbytes ()));            } in.close ();        Bd.close ();        } catch (Exception e) {e.printstacktrace ();            } finally{if (httpurlconn!=null) {httpurlconn.disconnect ();        }} try{System.out.println (New String (Datastring.tostring (). GetBytes ("GBK"), "Utf-8"));        }catch (Exception e) {e.printstacktrace (); } return Datastring.tostring ();} public static void Main (string[] arg) {http PM = new http ();p m.httpget ("http://132.xx.xxx.xx:8080/xxx//xxx?wsdl");}}

Have you ever felt that this XML is a bit more complicated to splice? This WebService server has soaphead security mechanism, there is no way, the client requires this to get. Let's introduce this WebService server with Soaphead security.

Reprint please indicate from whilejolly:http://blog.csdn.net/seedingly/article/details/39054609

"WebService" Debugging method chapter (II)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.