调用第三方接口查询手机号码归属地

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30331643/article/details/87267521

package redis;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
 
/**
 * @author YK
 * @date:2017-03-29 上午9:54  
 */
public class HttpReptileUtils {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        String url = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=17805428256";
        String json = loadJSON(url);
        System.out.println(json);
    }
 
    public static String loadJSON (String url) {
        StringBuilder json = new StringBuilder();
        try {
            URL oracle = new URL(url);
            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                                        yc.getInputStream(),"utf-8"));
            String inputLine = null;
            while ( (inputLine = in.readLine()) != null) {
                json.append(inputLine);
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return json.toString();
    }
}

猜你喜欢

转载自blog.csdn.net/qq_30331643/article/details/87267521