`

HttpClient4 get/post 总结(随时修改)

阅读更多

get方式提交

 

 

	public static String getHtml(String url) throws Exception {

		HttpGet httpGet = new HttpGet(url);
		HttpResponse response;
		String responseString = "";
		HttpEntity entity = null;
		try {
			response = httpclient.execute(httpGet);
			entity = response.getEntity(); // 返回服务器响应

			// EntityUtils --httpclient 4.1.4新特性.可以查看API得到
			// 这样获取返回的html就不需要象以前的打印流了
			responseString = EntityUtils.toString(response.getEntity()); //返回服务器响应のHTML代码

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (entity != null) {
				entity.consumeContent(); // 释放连接
			}

		}
		return responseString;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics