标签:
源码地址:https://github.com/juforg/websnapasimg

测试环境:http://localhost:7090/htmlsnapshot/snaphtml
调用方式 GET
| 参数名 | 说明 |
|---|---|
| htmlUrl | 需要将response的html进行截图的请求地址,需要URLEncoder.encode(htmlUrl,"UTF-8") |
| imgType | 生成图片的类型 如:PNG,GIF,JPG,BMP,RAF |
HttpClient client =newHttpClient();HttpMethod get =newGetMethod("http://localhost:8081/htmlsnapshot/snaphtml?htmlUrl=http%3A%2F%2Fsoa2.yundasys.com%3A8080%2Fydmobile%2Fbpsfinance%2Fzhengzhaosy%2F15346handler57090mbtmp.shtml&imgType=png");int status =-1;try{status = client.executeMethod(get);if(200== status){File file =newFile(path);//保存图片至本地的路径if(!file.getParentFile().exists()){file.getParentFile().mkdirs();}fos =newFileOutputStream(file);in = get.getResponseBodyAsStream();//获取流out =newBufferedOutputStream(fos);int i;while((i=in.read())!=-1){out.write(i);}out.flush();out.close();in.close();System.out.println("生成文件:"+path);}}catch(Exception e){;}finally{//释放资源get.releaseConnection();try{if(null!=out){out.close();}if(null!=in){in.close();}}catch(IOException e){e.printStackTrace();}}标签:
原文地址:http://www.cnblogs.com/juforg/p/5027667.html