Use Baidu API to query mobile phone number attribution

Source: Internet
Author: User
Tags stringbuffer
use Baidu API to query mobile phone number attribution

First to Baidu API website to view its relevant instructions, this is its official website: http://apistore.baidu.com/
A description can be found on this page.

Open the Web site can see several numbers belong to the query, some are charged, some free, if the call is not particularly frequent, the need for information is not particularly much, the free is enough. I started looking at the first interface: http://apistore.baidu.com/apiworks/servicedetail/117.html
But Baidu's own example can see that this interface does not meet my needs, I want to be able to query the provinces and cities, obviously this interface only returned to our province.

Look at this http://apistore.baidu.com/apiworks/servicedetail/794.html again.
First look at the results of the example given by Baidu:

It seems that this can be, Baidu gave several examples of different languages, I only look at the Java:

String Httpurl = "Http://apis.baidu.com/apistore/mobilenumber/mobilenumber";
String Httparg = "phone=15210011578";
String Jsonresult = Request (Httpurl, httparg);
System.out.println (Jsonresult);

/**
* @param urlall
*: Request Interface
* @param httparg
*: Parameters
* @return return result
*/
public static S Tring Request (String Httpurl, String httparg) {
BufferedReader reader = null;
String result = null;
StringBuffer SBF = new StringBuffer ();
Httpurl = Httpurl + "?" + Httparg;

try {
    url url = new URL (httpurl);
    HttpURLConnection connection = (httpurlconnection) URL
            . OpenConnection ();
    Connection.setrequestmethod ("get");
    Fill in the Apikey to the HTTP header
    connection.setrequestproperty ("Apikey",  "your own Apikey");
    Connection.connect ();
    InputStream is = Connection.getinputstream ();
    reader = new BufferedReader (new InputStreamReader (IS, "UTF-8"));
    String strread = null;
    while ((Strread = Reader.readline ())!= null) {
        sbf.append (strread);
        Sbf.append ("\ r \ n");
    }
    Reader.close ();
    result = Sbf.tostring ();
} catch (Exception e) {
    e.printstacktrace ();
}
return result;

}

Here side need to have their own Baidu Apikey can refer to this page http://app.baidu.com/static/cms/getapikey.html

This method can be encapsulated as a tool class used.

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.