通过Java访问指定url
2010-12-12 22:41
316 查看
通过Java的 URL、URLConnection可以获取指定url的 html文件
可以实现静态化某些页面的功能。
注意:
在初始化 URL时,可以带参数,使用? &,规则和在浏览器一样
比如: url = new URL("http://localhost/MySite/video.do?method=showAllByWatcher&uid="+uid);
ps:时常注意浏览器缓存,有时候很容易误导,以为是bug
codes:
可以实现静态化某些页面的功能。
注意:
在初始化 URL时,可以带参数,使用? &,规则和在浏览器一样
比如: url = new URL("http://localhost/MySite/video.do?method=showAllByWatcher&uid="+uid);
ps:时常注意浏览器缓存,有时候很容易误导,以为是bug
codes:
PrintWriter out=null; try { out = new PrintWriter( location+folder+"/video/index.html","UTF-8" ); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } URL url=null; try { //这是新闻的主页,要根据部署的服务器url,修改 url = new URL("http://localhost/MySite/video.do?method=showAllByWatcher&uid="+uid); } catch (MalformedURLException e) { e.printStackTrace(); } BufferedReader r=null; try { URLConnection con=url.openConnection(); r = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8")); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } String str=""; do{ try { str=r.readLine(); } catch (IOException e) { e.printStackTrace(); } // System.out.println(str); out.println(str); }while(str!=null); out.flush(); out.close(); try { r.close(); } catch (IOException e) { e.printStackTrace(); }
相关文章推荐
- 通过代理实现Java代码访问指定URL
- 通过Java访问指定url
- java.net.URL如何通过proxy访问internet资源
- java通过指定的URL获取图片信息(长宽)
- JAVA通过访问页面中的URL实现Http文件下载到本地
- java项目中普遍存在的一个bug,用户直接可以通过url访问本人没有权限的页面
- java web 如何创建一个可供访问的文件(通过url访问)
- java在线截图---通过指定的URL对网站截图
- Java实现访问指定url,并在指定时长后自动关闭浏览器
- java 通过Ajax前台传参数 并用 HttpURLConnection Post方式访问对外的接口
- java通过名称访问url查询经纬度(名称越详细经纬度越精确)
- 小工具-使用java SSL通过url获得访问转为String-http/https
- Java中通过代理连接至指定的URL
- IE6 jQuery.ajax 不能访问服务器(未执行URL指定的java处理类)
- 关于安卓开发当中通过java自带的HttpURLConnection访问XML的java.io.EOFException问题
- java.net.URL如何通过proxy访问internet资源
- JAVA通过访问页面中的URL实现Http文件下载到本地
- java网络编程中向指定URL发送GET POST请求示例
- 通过SAS connect drvier for java 来访问SAS
- 通过URL对象获取指定网页的内容