HttpClient的getResponseBodyAsString()返回空字符串啊怎么回事 HttpClient 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 测试可以不? public static void main(String[] args) { //构造HttpClient的实例 HttpClient httpClient = new HttpClient(); //创建GET方法的实例 GetMethod getMethod = new GetMethod("http://www.ibm.com"); //使用系统提供的默认的恢复策略 getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); try { //执行getMethod int statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + getMethod.getStatusLine()); } //读取内容 byte[] responseBody = getMethod.getResponseBody(); //处理内容 System.out.println(new String(responseBody)); } catch (HttpException e) { //发生致命的异常,可能是协议不对或者返回的内容有问题 System.out.println("Please check your provided http address!"); e.printStackTrace(); } catch (IOException e) { //发生网络异常 e.printStackTrace(); } finally { //释放连接 getMethod.releaseConnection(); } } 急求!webservice接口实现存储下载接口 思想-试想 我是否能这样想 .. xfire 1.2 jdk 1.5 enum 报错 求JAVA写一个配上音乐的简单程序! 一道java面面试题,迷糊了 ----------------java面试题 关于编码转换??高分相送!!! 应用struts时出错 Javamail的mail.jar怎么用啊?急!!! 跪求一个ssm网店系统 spring最新的网站上怎么下载spring包啊!?? JSP版的CMS系统 - 免费者内容管理系统,免费开源发布
//构造HttpClient的实例
HttpClient httpClient = new HttpClient();
//创建GET方法的实例
GetMethod getMethod = new GetMethod("http://www.ibm.com");
//使用系统提供的默认的恢复策略
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
try {
//执行getMethod
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: "
+ getMethod.getStatusLine());
}
//读取内容
byte[] responseBody = getMethod.getResponseBody();
//处理内容
System.out.println(new String(responseBody));
} catch (HttpException e) {
//发生致命的异常,可能是协议不对或者返回的内容有问题
System.out.println("Please check your provided http address!");
e.printStackTrace();
} catch (IOException e) {
//发生网络异常
e.printStackTrace();
} finally {
//释放连接
getMethod.releaseConnection();
}
}