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.