• 新浪ip地址查询接口调用方面


     

    import com.cdeledu.plat.fin.common.util.URLUtil;
    import com.cdeledu.plat.fin.common.util.WebPage;
    import com.google.gson.Gson;
    import com.google.gson.JsonElement;
    import com.google.gson.JsonObject;
    import com.google.gson.JsonParser;

    public class IpLookUp
    {
     private static String sinaURL = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=";

     public static String sinaIpLookup(String ip)
     {
      String pageURL = sinaURL;
      WebPage webPage = null;
      String json = "";
      webPage = URLUtil.getPageContent(pageURL + ip);
      if(webPage != null && webPage.getHtml() != null)
      {
       json = webPage.getHtml();
       String begin = "{";
       String end = "}";
       json = json.substring(json.indexOf(begin), json.indexOf(end) + 1);
      }
      return json;
     }
     public static IpInfo parserSinaLoopkUpIpInfo(String json)
     {
      Gson gson = new Gson();
      IpInfo ipInfo = null;
      JsonParser parser = new JsonParser();
      JsonElement jsonElement = parser.parse(json);
      if(jsonElement.isJsonObject())
      {
       JsonObject JsonObject = (JsonObject)jsonElement;
       ipInfo = gson.fromJson(JsonObject, IpInfo.class);
       if(ipInfo != null)
       {
        System.out.println(ipInfo.getStart() + "\t" + ipInfo.getEnd() + "\t" + ipInfo.getProvince());
       }
      }
      return ipInfo;
     }
     /**
      * @param args
      */
     public static void main(String[] args)
     {
      String ip = "219.232.43.228";
      ip = "218.94.132.146";
      long start = System.currentTimeMillis();
      String json = sinaIpLookup(ip);
      IpInfo ipInfo = parserSinaLoopkUpIpInfo(json);
      System.out.println(ipInfo);
      System.out.println("===times===" + (System.currentTimeMillis() - start));
     }

  • 相关阅读:
    函数组件在react懒加载的方式
    axios 封装
    react高阶组件+ref转发的组合使用
    Iterator & Iterable 和 Comparable&Comparator
    java.lang.Collections
    虚拟机类加载学习和思考
    垃圾收集器与内存分配策略
    jvm内存区域与内存溢出
    spring装配Bean过程
    索引知识点补充
  • 原文地址:https://www.cnblogs.com/something/p/3102062.html
Copyright © 2020-2023  润新知