根据ip获取地理位置java(调用淘宝接口)
发布日期:2021-08-26 09:44:26 浏览次数:4 分类:技术文章

本文共 1158 字,大约阅读时间需要 3 分钟。

hot3.png

URL url = new          URL("http://ip.taobao.com/service/getIpInfo.php?ip="+"27.223.68.94");          HttpURLConnection connection = (HttpURLConnection)          url.openConnection(); connection.setDoOutput(true);         connection.setDoInput(true); connection.setRequestMethod("POST");          connection.setUseCaches(false);          connection.setInstanceFollowRedirects(true);          connection.setRequestProperty("Content-Type",          "application/x-www-form-urlencoded");                    connection.connect();                            JSONObject jsono = new JSONObject(new JSONTokener(                new InputStreamReader(connection.getInputStream())));        String city = "";        String rep = jsono.toString();        String[] s = rep.split(",");        for (int i = 0; i < s.length; i++) {            if (s[i].contains("市")) {                if (s[i].length() > 8) {                    city = s[i].substring(8, s[i].length() - 2);                    break;                } else {                    city = "";                }            }        }        System.out.println(city);

转载于:https://my.oschina.net/angleshuai/blog/354876

转载地址:https://blog.csdn.net/weixin_33881753/article/details/92442540 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:多线程同步问题
下一篇:java concurrent包的学习(转)

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月06日 09时29分22秒