HttpClient

来源:互联网 发布:韦德体测数据 编辑:程序博客网 时间:2024/05/31 19:19
  public static String url="http://v.juhe.cn/toutiao/index?key=22a108244dbb8d1f49967cd74a0c144d&type=yule";

    public static String params(String method){
        StringBuffer buffer=new StringBuffer();
        HttpClient client=new DefaultHttpClient();
        if(method.equals("GET")){

            try {
                HttpGet httpGet=new HttpGet(url);
                HttpResponse response=client.execute(httpGet);

                HttpEntity etity=response.getEntity();
                InputStream in=etity.getContent();


                BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(in));
                String line=null;
                while((line=bufferedReader.readLine()) != null){
                    buffer.append(line);
                }

                return buffer.toString();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return null;
原创粉丝点击