首页 > Web开发 > 详细

httpclient

时间:2015-05-26 10:53:08      阅读:299      评论:0      收藏:0      [点我收藏+]

每次用,每次查,每次查,每次忘,这下忘不了了吧!

另,要这两个包,技术分享

public void getResponseDetail(String url) {
		HttpServletResponse response = (HttpServletResponse) super.getContextParam(ServletActionContext.HTTP_RESPONSE);
		HttpClient httpClient = new HttpClient();
		GetMethod getMethod = new GetMethod(url);
		try {
			//关闭连接
			getMethod.setRequestHeader("Connection","close");
			getMethod.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
			int statusCode = httpClient.executeMethod(getMethod);
			if (statusCode != HttpStatus.SC_OK) {
				System.out.println("Method failed:"
						+ getMethod.getStatusLine());
			} else {
				String json = getMethod.getResponseBodyAsString();
				renderText(response, FormatJson.showJson(json));
			}
			getMethod.releaseConnection();
		} catch (Exception e) {
			log.error("ProControlAction Exception,url = " + url, e);
		}
	}



httpclient

原文:http://my.oschina.net/u/1432304/blog/419923

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!