当前位置:网站首页>Tencent resolves the address according to the IP address

Tencent resolves the address according to the IP address

2022-04-23 16:49:00 A coir boat in the broken white clouds

// Need to apply to Tencent key
private static String TXURL = "https://apis.map.qq.com/ws/location/v1/ip?key=&ip=";
public static String getTXCityCodeByIp(String ip) {
    
                CloseableHttpClient httpClient = HttpClients.createDefault();
                try {
    
                        String requestURL = String.format("%s%s", TXURL, ip);
                        HttpGet getMethod = new HttpGet(requestURL);
                        HttpResponse response = httpClient.execute(getMethod);
                        if (null != response && response.getStatusLine().getStatusCode() == 200) {
    
                                return EntityUtils.toString(response.getEntity(), "UTF-8");
                        }
                } catch (Exception e) {
    
                        log.error("getTXCityCodeByIp ip:[{}] is Exception:{}", ip, e.toString());
                } finally {
    
                        try {
    
                                httpClient.close();
                        } catch (IOException e) {
    
                                log.error(e.toString());
                        }
                }
                return null;
        }
        
        public static void main(String[] args) {
    
                String ip = "";
                System.out.println(getTXCityCodeByIp(ip));
        }

版权声明
本文为[A coir boat in the broken white clouds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231400067875.html