您的位置 首页 java

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

java 获取手机号归属地

一般想获取手机号归属地等信息个人是无法获取的,但是可以通过调用第三方接口获取,具体百度搜索很多

这里例子提供一个淘宝的接口 ,该功能已经发布到网站作为一个在线小工具,

拿走不谢:

用都的jar httpClient相关

代码:

 public class HttpTool {

/**
 * 手机号地区接口
 * @param request
 * @return
 */private final static String iphoneurl = "#34;;

/**
 * http请求
 * @return
 * @throws Exception
 */public static String doHttpgetAPi(String url)  throws Exception {
HttpGet post = null;
  close ableHttpResponse response = null;
    try {
     Close ableHttpClient 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"}}  

文章来源:智云一二三科技

文章标题:使用java获取手机号归属地等信息httpClient实现

文章地址:https://www.zhihuclub.com/187910.shtml

关于作者: 智云科技

热门文章

网站地图