Let's take a look at the image below.
In the hao123 interface, you only need to enter a mobile phone number, whether it is mobile, Unicom, or Telecom. You can click query to directly query the home location, and number type, such as on the Internet.
There are a lot of websites. I will take this as an example. How can we put this information on our own website?
Let's analyze it first. In fact, it is very convenient. We can open this interface in ie9 and then use the tool-developer tool, or install F12 directly, as shown in figure
First, click the network and then click Start capture. Then, click search to see what will happen.
Is there two integers? The first is obviously loading the information of the region where we entered the number, and the first is loading an image, which is of no use to us.
Click the first method to see what is captured
URL
Http://vip.showji.com/locating? M = 13888888888 & outfmt = JSON & callback = phone. Callback this is obviously a GET request. You only need to request this address to get the following result.
Phone. callback ({"mobile": "13888888888", "queryresult": "true", "Province": "Yunnan", "city": "Kunming", "areacode ": "0871", "postcode": "650000", "corp": "China Mobile", "card": "GSM "});
Use the mobile phone number, province, city, zip code, number type, and other information. If this is the case, just copy the region to the address bar. Let's take a look at the effect.
That's right. It's what we want. Don't worry. The rest can be simpler. Let's take a look at this URL.
Http://vip.showji.com/locating? M = 13888888888 & outfmt = JSON & callback = phone. Callback
What if now I keep the delete after this rules number in http://vip.showji.com/locating? M = 13888888888 what will happen?
Put it in the address bar and try the effect.
It's amazing. What we get is an XML file.
This is as simple as calling webservces. We only need to write a program to request this address to get the desired effect.
Create a project. Let's take a look.
I did not analyze the code step by step.
Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using system. net; using system. io; using system. security. cryptography. x509certificates; using system. net. security; using system. security. cryptography; using system. XML; namespace ccbtext {public partial class form2: FORM {public Form2 () {initializecomponent ();} private void form2_load (Object sender, eventargs e) {} this method is not used here, you can use this as a reference /// <summary> /// enter the URL to return the HTML code of the webpage /// </Summary> /// <Param name = "url"> URL </param> // <returns> </returns> Public String geturltohtml (string URL) {stringbuilder content = new stringbuilder (); try {// create an HTTP request httpwebrequest request = (httpwebrequest) webrequest with the specified URL. create (URL); reque St. keepalive = false; // get the response of the corresponding HTTP request httpwebresponse response = (httpwebresponse) request. getresponse (); // get the response stream responsestream = response. getresponsestream (); // access the response stream (in the "GBK" Character Set) streamreader sreader = new streamreader (responsestream, encoding. getencoding ("UTF-8"); // starts reading data char [] sreaderbuffer = new char [256]; int COUNT = sreader. read (sreaderbuffer, 0,256); While (count> 0) {string Tempstr = new string (sreaderbuffer, 0, count); content. append (tempstr); Count = sreader. read (sreaderbuffer, 0,256);} // read the sreader. close () ;}catch (exception) {content = new stringbuilder ("runtime error");} return content. tostring () ;}/// <summary> // check whether the query is performed properly. If the query meets the following rules, you can use /// to return the nodes that need to be ordered: /// queryresult (Query Result Status is true, false) // province (province) // City (region) // Corp (Service Provider) /// card (card type GS M) // areacode (area code) // postcode (ZIP code) /// </Summary> /// <Param name = "url"> </param> /// <Param name = "mobilenum"> </param> /// <returns> </returns> Public static string [] getinfobyxml (string URL, string mobilenum) {try {xmldocument xml = new xmldocument (); // XML. loadxml ("<? XML version = '1. 0' encoding = 'utf-8'?> <Queryresponse xmlns = 'HTTP: // api.showji.com/locating/'> <mobile> 15890636739 </mobile> <queryresult> true </queryresult> <province> Henan </province> <city> Zhengzhou </city> <areacode> 0371 </areacode> <postcode> 450000 </postcode> <Corp> China Mobile </Corp> <card> GSM </card> </queryresponse> "); XML. load (string. format (URL, mobilenum); xmlnamespacemanager xmlnm = new xmlnamespacemanager (XML. nametable); xmlnm. addnamespace ("content", "HTTP: // Api.showji.com/locating/ "); xmlnodelist nodes = xml. selectnodes ("// content: queryresult | // content: Mobile | // content: province | // content: City | // content: Corp | // content: card | // content: areacode | // content: postcode ", xmlnm); If (nodes. count = 8) {If ("true ". equals (nodes [1]. innertext) {return New String [] {nodes [0]. innertext, nodes [2]. innertext + nodes [3]. innertext, nodes [6]. innertext + nodes [7]. inn Ertext, nodes [4]. innertext, nodes [5]. innertext };}return New String [] {"false" };}catch {return New String [] {"false "};}} // call the method to query data private void button#click (Object sender, eventargs e) {foreach (string item in getinfobyxml ("http://vip.showji.com/locating? M = {0} ", txtmobile. Text. Trim () {richtextbox1.text + =" _ "+ item ;}}}}
Run the command to check the effect.
I use winfrom for testing. If you want to use ASP. Net is the same. Copy my method to the CS code on your web page.
Now our analysis is over,
Here, I will add a call Method for calling a website with a certificate to dakong.
Because all the files with the certificate are to be verified, we will directly ask him to perform local callback verification here. In this case, we need to rewrite the method. Let's take a look at the callback method.
// Callback Verification Certificate problem public bool checkvalidationresult (Object sender, x509certificate certificate, x509chain chain, sslpolicyerrors errors) {// always accept return true ;}
Others are quite simple. Just add a few lines of code to the above method geturltohtml (). The modified method
/// <Summary> /// enter the URL to return the HTML code of the webpage // </Summary> /// <Param name = "url"> URL </param>/ // <returns> </returns> Public String geturltohtml (string URL) {stringbuilder content = new stringbuilder (); try {// create an HTTP request servicepointmanager with the specified URL. servercertificatevalidationcallback = new system. net. security. remotecertificatevalidationcallback (checkvalidationresult); // verify httpwebrequest request = (httpwebrequest) webrequest. create (URL); Request. keepalive = false; request. useragent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; slcc2 ;. net CLR 2.0.50727 ;. net CLR 3.5.30729 ;. net CLR 3.0.30729; Media Center PC 6.0; infopath.2; MS-RTC lm 8 ;. net4.0c ;. net4.0e) "; request. method = "get"; request. accept = "*/*"; // create the Certificate file x509certificate objx509 = new x509certificate (application. startuppath + "\ 123.cer"); // Add it to the request. clientcertificates. add (objx509); httpwebresponse response = (httpwebresponse) request. getresponse (); // get the response of the corresponding HTTP request // get the response stream responsestream = response. getresponsestream (); // access the response stream (in the "GBK" Character Set) streamreader sreader = new streamreader (responsestream, encoding. getencoding ("GBK"); // starts reading data char [] sreaderbuffer = new char [256]; int COUNT = sreader. read (sreaderbuffer, 0,256); While (count> 0) {string tempstr = new string (sreaderbuffer, 0, count); content. append (tempstr); Count = sreader. read (sreaderbuffer, 0,256);} // read the sreader. close () ;}catch (exception) {content = new stringbuilder ("runtime error");} return content. tostring ();}
You can also use third-party interfaces.
Http://www.sucha100.com/service/query.asmx