首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

HttpClient不能实例化的有关问题如何解决

2013-10-27 
HttpClient不能实例化的问题怎么解决测试使用httpclientpublic class TestJetty {public static void main

HttpClient不能实例化的问题怎么解决
测试使用httpclient

public class TestJetty {
   public static void main(String[] args) {
   HttpClient httpClient = new HttpClient();
   GetMethod getMethod = new GetMethod("http://www.baidu.com/");
   try {
   getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    new DefaultHttpMethodRetryHandler());
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 (Exception e) {
e.printStackTrace();
}finally{
getMethod.releaseConnection();
}
   }
}

但是执行报错:Cannot instantiate the type HttpClient,求大侠帮忙

我就估计会有人遇到这种问题

别用4.X版本的 用3.X的  升级后那个类变成接口了 

热点排行