http访问页面

private static final String HTML_PATH ="\\var\\wwww\\html\\shop\\index.html";
	
	public boolean copyHtml(){
		boolean flag = false;
		String response =null;
		File htmlFile =null;
		HttpClient client = new HttpClient();
		//主机+端口号+协议,http默认80
	    client.getHostConfiguration().setHost("shop.ssports.com", 80, "http"); 
	    HttpMethod method = new GetMethod();
	    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());//恢复策略默认重发三次,也可以自定义,实现HttpMethodRetryHandler
	    try {
	    	int statusCode=client.executeMethod(method);
	    	if(statusCode==HttpStatus.SC_OK){
	    		//状态码如不对,表示访问不成功
	    		response =method.getResponseBodyAsString();
	    		htmlFile =new File(HTML_PATH); 
	    		if(htmlFile.exists()) htmlFile.delete();
	    		FileCopyUtils.copy(response.getBytes("UTF-8"), htmlFile);
	    		flag = true;
	    	}
	    } catch (Exception e) {
	    	e.printStackTrace();
	    	flag = false;
	    }
	    //必须要释放连接
	    method.releaseConnection();
	    
	    return flag;
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值