使用spring中restTemplate的api发送请求下载图片


       String url = "https://img3.doubanio.com/view/status/l/public/103861781-665301078817f01.jpg";
       //创建restTemplate对象
        org.springframework.web.client.RestTemplate restTemplate = new org.springframework.web.client.RestTemplate();
        /**
         * 请求地址
         * 请求方式
         * 请求实体类
         * 请求返回类型
         */
        ResponseEntity<byte[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, byte[].class);
        //获取entity中的数据
        byte[] body = responseEntity.getBody();
        //创建输出流  输出到本地
        FileOutputStream fileOutputStream = new FileOutputStream(new File("F:\\fuwuqi\\1.jpg"));
        fileOutputStream.write(body);
        //关闭流
        fileOutputStream.close();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM