关闭

知乎专栏API

标签: 知乎API
657人阅读 评论(0) 收藏 举报
分类:
String url = "http://zhuanlan.zhihu.com/api/columns/oh-hard/posts/20332126";
        //String url = "http://zhuanlan.zhihu.com/api/columns/tastespirit/posts/20306620";

        HttpURLConnection conn = null;
        try {
            conn = (HttpURLConnection) new URL(url).openConnection();
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");
            conn.setRequestProperty("contentType ", "zh-CN");
            conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
            conn.setRequestProperty("Accept-Language ", "zh-CN,zh;q=0.8");

            InputStream inputStream = conn.getInputStream();



            String result = "";
            InputStream urlStream = new GZIPInputStream(inputStream);  
            BufferedReader in = new BufferedReader(new InputStreamReader(urlStream,"utf-8"));  
            String line = "";  
            while ((line = in.readLine()) != null) {
                result += line;
            }
            System.out.println(result);



        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14237次
    • 积分:268
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:4篇
    • 译文:0篇
    • 评论:20条
    文章分类
    最新评论