通过Java代码实现手机号归属地查询
来源:互联网 发布:软件安全性测试方法 编辑:程序博客网 时间:2024/09/21 09:18
所需工具:1、elipse 2、json所需jar包
代码:
package com.mobilephone;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import net.sf.json.JSONObject;
public class MainActivity {
/**
* @param urlAll
* :请求接口
* @param httpArg
* :参数
* @return 返回结果
*/
public static String 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");
// 填入apikey到HTTP header
connection.setRequestProperty("apikey", "73d6548dfb7223d3421608255a592ac3");
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;
}
public static void main(String[] args) {
String resout = "";
String httpUrl = "http://apis.baidu.com/apistore/mobilenumber/mobilenumber";
String phonenum = "110";
String httpArg = "phone=" + phonenum;
String jsonResult = request(httpUrl, httpArg);
System.out.println(jsonResult);
JSONObject obj = JSONObject.fromObject(jsonResult);
String code = obj.get("errNum").toString();
if (code.equals("0")) {
JSONObject obj2 = (JSONObject) obj.get("retData");
resout = obj2.get("province") + "-" + obj2.get("city") + "-" + obj2.get("supplier") + "-"
+ obj2.get("suit");
} else {
resout = obj.get("retMsg").toString();
}
System.out.println(resout);
}
}
- 通过Java代码实现手机号归属地查询
- java 手机号归属地查询
- 手机号归属地查询
- 查询手机号归属地
- 根据手机号查询归属地
- 根据手机号查询归属地
- 手机号归属地查询接口
- 手机号的归属地查询
- Java 实现手机号的归属地查询 手机号码的卡的类型
- python实现手机号归属地相关信息查询
- java手机号归属地验证
- java获取手机号归属地
- 归属地查询代码
- 根据手机号 查询手机归属地信息
- android Webservice 手机号归属地查询
- 调用webservice查询手机号归属地
- 利用百度API查询手机号归属地
- IP、域名、手机号归属地查询
- 性能优化之Hibernate缓存讲解、应用和调优
- iOS :GCD的简单实用
- python爬虫学习笔记2——百度贴吧帖子爬取
- 欢迎使用CSDN-markdown编辑器
- iOS 中使用 Mobile Installation 安装 IPA(使用iTunes/AppStore一样的安装API)
- 通过Java代码实现手机号归属地查询
- 文案编写的X与Y型
- 我们不需要供奉谭浩强
- Xamarin.Forms入门困扰与解决方式-No.5
- 遗忘在角落的好看瓶子中的幸运星
- C++11学习笔记5---智能指针
- oracle11g rac环境中的Admin-managed和Policy-Managed
- sql行转列-pivot
- SwipeRefreshLayout下拉刷新冲突解决