Call a phone number attribution query API from scratch

Source: Internet
Author: User

Since the life of a programmer, there are always more or less mention of some API (application interface), online various introductory tutorials, examples of a lot of, some just paste some code, and do not give comments, write demo when even compile can not pass. Below I started to introduce the detailed steps of lowering the mobile phone API

1. Preparation, check the relevant interface information, part of the commercial time charge

Interface address http://sj.apidata.cn/Request parameters
Name of parameter parameter Description
Mobile The phone number to be queried.
Callback You need to specify callback when you need to return data in JSONP format.
Request Example http://sj.apidata.cn/?mobile=13488888888 return field
Field name field type Field description
status integer interface request Status: 0 = Request failed, 1 = Request succeeded
data object result data object returned
message string return message, reason for failure when request fails
Data node Field Description:
Field name field Type Field Description
Prefix Integer Mobile number segment.
Mobile String Search for mobile phone number
Province String Name of the province to which it belongs.
City String City name of the place of attribution
Isp String Name of the carrier to which it belongs
Code Integer Place of attribution Administrative number
ZipCode Integer Place of Attribution postal code
Types String Mobile Phone number card information
return example{
    "Status":1,"Data":{"prefix":138 "province":  "Yunnan"  "City":  "ISP":  "move"  "code": 871 "ZipCode": 650500 "types":  "China Mobile GSM"   "mobile": " 13888888888 "}                 " success "} 


2. Sending requests, processing return results
  Private voidGetnuminform (stringnum) {            stringURL ="http://sj.apidata.cn/?mobile="+num; //Please find the numbersHttpWebRequest res =(HttpWebRequest) webrequest.create (URL); //Method NameRes. Method ="GET"; //access to operatesHttpWebResponse resp =(HttpWebResponse) Res.                       GetResponse (); //To read a digital streamStreamReader sr =NewStreamReader (resp.            GetResponseStream (), Encoding.UTF8); //encode into a string            stringresphtml =Sr.                        ReadToEnd (); #regionDemo1//Get JSON imagesNumdes numdes = jsonconvert.deserializeobject<numdes>(resphtml); stringCity = numdes.data[" City"].            ToString (); stringISP = numdes.data["ISP"].            ToString (); #endregion                        #regionDemo2Jobject numdbers=Jobject.parse (resphtml); stringc = numdbers["Data"][" City"].            ToString (); #endregionTextBox2.Text= City +ISP; }

3. Call the serialization library, otherwise unrecognized jobject, JsonConvert object, vs comes with a nuget package, which has the Newtonsoft package we need, just need to install to

Open: Tools-nuget Package Manager-Package Manager console

Input: Install-package Newtonsoft.json

If you are prompted to fail the installation, or if the version is inconsistent and you need to upgrade to the latest version of NuGet, then uninstall the NuGet package in the management list and then reinstall the latest version

4. For the Numdes object above Demo1, you need to create a new entity class that creates a property corresponding to the interface Web site return value, in http://sj.apidata.cn/, the fields returned are: stasus, data, message, So write the corresponding member field in the new class, as follows

   Public class Numdes    {        publicintgetset;}          Public dictionary<string,stringgetset;}          Public string Get Set ; }    }

5. Start the program and get the returned city, operator



   


/span>

Zero-based call to a phone number attribution query API

Related Article

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.