使用java获取手机号归属地等信息httpClient实现

java获取手机号归属地一般想获取手机号归属地等信息个人是无法获取的,但是可以通过调用第三方接口获取,具体百度搜索很多
这里例子提供一个淘宝的接口 ,该功能已经发布到网站作为一个在线小工具,
拿走不谢:
http://www.yzcopen.com/con/iphone
用都的jar  httpClient相关
代码:
    

    public class HttpTool {

    /**
     * 手机号地区接口
     * @param request
     * @return
     */
    private final static String iphoneurl = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=";

    /**
     * http请求
     * @return
     * @throws Exception
     */
    public static String doHttpgetAPi(String url)  throws Exception {
        HttpGet post = null;
         CloseableHttpResponse response = null;
        try {
            CloseableHttpClient httpClient = HttpClients.createDefault();
             post = new HttpGet(url);
            // 构造消息头
             post.setHeader("Content-Type", "application/json; charset=utf-8");
             post.setHeader("Connection", "Close");
             response =  httpClient.execute(post);
            if(response != null){
                  HttpEntity entity=response.getEntity();  
                    String str=EntityUtils.toString(entity); 
                  return str;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if(response!=null){
                response.getEntity().getContent().close();
            }
            if(post != null){
                try {
                    post.releaseConnection();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    
    public static void main(String[] args) {
        String ipurl = iphoneurl+"您的手机号";
        String result = HttpTool.doHttpgetAPi(url);
        System.out.println(result );
    }
  }

通过执行返回的结果是:
{"response":{"13854510856":{"detail":{"area":[{"city":"烟台"}],"province":"山东","type":"domestic","operator":"移动"},"location":"山东烟台移动"}},"responseHeader":{"status":200,"time":1579079131507,"version":"1.1.0"}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值