springboot实现查询手机号归属地

springboot实现查询手机号归属地我也不知道咋写的,测试过了,反正能用就行;packagecom.example.needs.util;importorg.apache.http.HttpEntity;importorg.apache.http.ParseException;importorg.apache.http.client.methods.CloseableHttpResponse;importorg.apache.http.client.methods.HttpGet;importorg.apache.h

大家好,又见面了,我是你们的朋友全栈君。

我也不知道咋写的,测试过了,反正能用就行;

	   <!--httpclient依赖包-->
       <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
        <!--日志包-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>
package com.example.needs.util;

import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.*;


public class TextUtil { 
   
    public static void main(String[] args) throws IOException { 
   
        FileWriter fileWriter = new FileWriter("D:/Lianxi/zidian.txt");
        String httpUrl = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=";

        String zd = "";
        for (int i = 0; i < 100; i++) { 
   
            if (i >= 10) { 
   
                zd = "1785" + String.valueOf(i) + "08019";
            } else { 
   
                zd = "178500" + String.valueOf(i) + "08019";
            }

            String js = doGet(httpUrl,zd);
            if (js.contains("山东")){ 
   
                fileWriter.write(zd+"\r\n");
            }

        }
        fileWriter.flush();
        fileWriter.close();
    }

    /** * 发送HttpGet请求 * @param url * @return */
    public static String doGet(String url,String zd) { 
   
        //1.获得一个httpclient对象
        CloseableHttpClient httpclient = HttpClients.createDefault();
        //2.生成一个get请求
        HttpGet httpget = new HttpGet(url+zd);
        CloseableHttpResponse response = null;
        try { 
   
            //3.执行get请求并返回结果
            response = httpclient.execute(httpget);
        } catch (IOException e1) { 
   
            e1.printStackTrace();
        }
        String result = null;
        try { 
   
            //4.处理结果,这里将结果返回为字符串
            HttpEntity entity = response.getEntity();
            if (entity != null) { 
   
                result = EntityUtils.toString(entity);
            }
        } catch (ParseException | IOException e) { 
   
            e.printStackTrace();
        } finally { 
   
            try { 
   
                response.close();
            } catch (IOException e) { 
   
                e.printStackTrace();
            }
        }
        return result;
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/163175.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • dubbo常见的一些面试题「建议收藏」

    dubbo常见的一些面试题「建议收藏」dubbo常见的一些面试题

    2022年4月21日
    40
  • rstrip python_Python strip()、split()和rstrip()方法

    rstrip python_Python strip()、split()和rstrip()方法1.Pythonstrip()语法描述:Pythonstrip()方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列。注意:该方法只能删除开头或是结尾的字符,不能删除中间部分的字符。返回值:返回值是返回移除字符串头尾指定的字符生成的新字符串示例:a1=”00000123hello_world12300000000″printa1.strip(“0”)#去除首尾字符0a2…

    2025年6月18日
    0
  • jdk动态代理invoke方法自动运行原因

    jdk动态代理invoke方法自动运行原因invoke方法介绍想要知道invoke方法为什么会自动调用我们先要来了解一下这个方法publicinterfaceInvocationHandler{publicObjectinvoke(Objectproxy,Methodmethod,Object[]args)首先该方法来自于接口InvocationHandler,该接口中仅有一个invoke方法,该…

    2022年5月1日
    43
  • nginx随着passenger构造ruby on rails页

    nginx随着passenger构造ruby on rails页

    2022年1月11日
    54
  • jmeter测试并发200_jmeter并发测试实例

    jmeter测试并发200_jmeter并发测试实例相对并发和绝对并发相对并发:指在一个时间段内发生的事情 绝对并发:指在同一时刻发生的事情一:相对并发在jmeter的测试计划中添加线程组,设置线程属性,2秒之内启动2000个线程,其对应的相对并发为1000(线程数/启动时间)二:绝对并发一般使用同步定时器实现绝对并发,即当所有请求集合完毕之后一块出发1、jmeter线程组里面可以简单设置多线程,但是当你设置1秒钟50个线程时去看结果其实50个请求跑完并不是在1秒钟之内2、由于测试的机器本身性…

    2022年9月1日
    3
  • Robotium 常用方法

    Robotium 常用方法①点击:clickOnButton(int)//ClicksonaButtonwithagivenindex.clickOnButton(String)//ClicksonaButtonwithagiventext.clickOnCheckBox(int)//ClicksonaCheckBoxwithagivenindex.clickOnVie

    2022年7月25日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号