The method of realizing the query of number attribution by Android programming _android

Source: Internet
Author: User
Tags soap

This article is an example of the Android programming implementation of the number attribution Query method. Share to everyone for your reference, specific as follows:

By sending the XML access WebService we can implement the number attribution query, we can use the format of the XML provided by the proxy server to set up, and then request to submit to the server, the server will be returned to a xml,xml on request to encapsulate the data we want to get.

Send XML

1. Open a httpurlconnection via URL encapsulation path

2. Set the request mode, Content-type and Content-length

The content-type of the XML file is: Application/soap+xml; Charset=utf-8

3. Obtain output stream output data using HttpURLConnection

WebService

1.WebService is an API published on the network that can be invoked by sending XML, WebService return results are also XML data

2.WebService has no language restrictions, as long as you can send XML data and receive XML data

There are a number of webservice services available on the 3.http://www.webxml.com.cn/website that we can call

A description of the use of the telephone attribution query is provided in the 4.http://webservice.webxml.com.cn/webservices/mobilecodews.asmx?op=getmobilecodeinfo

Effect Chart:

Core code:

public class Xmlservice {public string query (String num) throws Exception {InputStream in = This.getclass (). GETCL
    Assloader (). getResourceAsStream ("Query.xml");
    byte[] data = Loadutils.load (in);
    string xml = new string (data);
    Replace XML = Xml.replace ("#", num);
    byte[] SendData = xml.getbytes ("UTF-8");
    URL url = new URL ("Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx") on the address sent to the proxy;
    HttpURLConnection conn = (httpurlconnection) url.openconnection ();
    Conn.setrequestmethod ("POST"); Conn.setrequestproperty ("Content-type", "application/soap+xml;
    Charset=utf-8 ");
    Conn.setrequestproperty ("Content-length", String.valueof (Senddata.length));
    Send the requested XML out Conn.setdooutput (true);
    Conn.getoutputstream (). write (SendData);
    Gets the data returned from the server if (conn.getresponsecode () = =) return Parse (Conn.getinputstream ());
  return null; }//Parse stream get data in Getmobilecodeinforesult private String parse (InputStream inputstream) tHrows Exception {xmlpullparser parser = Xml.newpullparser ();
    Parser.setinput (InputStream, "UTF-8"); Find the Getmobilecodeinforesult tag, get the data for the label (int event = Parser.geteventtype (); event!= xmlpullparser.end_document; Ev ent = parser.next ()) switch (event) {case XmlPullParser.START_TAG:if ("Getmobilecodeinforesult").
      Equals (Parser.getname ())) return Parser.nexttext ();
  return null;
 }
}

The sent XML encapsulates the phone number (Query.xml):

<?xml version= "1.0" encoding= "Utf-8"?> <soap12:envelope xmlns:xsi=
"http://www.w3.org/2001/" Xmlschema-instance "xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:soap12=" http://www.w3.org/2003/05/ Soap-envelope ">
 <soap12:Body>
  <getmobilecodeinfo xmlns=" http://WebXml.com.cn/">
   < mobilecode>#</mobilecode>
   <userID></userID>
  </getMobileCodeInfo>
 </ Soap12:body>
</soap12:Envelope>

I hope this article will help you with the Android program.

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.