2011-11-03 37 views
0

我已经努力解决这个问题,但我不能。我试图从apache使用httpClient 4.1.2。作为逻辑,我从这个例子开始,问题是我有一些奇怪的错误,我不明白。这是处理:ClientWithResponseHandler示例给出一个ERROR?

package ClientWithResponseHandler; 
    import org.apache.http.client.ResponseHandler; 
    import org.apache.http.client.HttpClient; 
    import org.apache.http.client.methods.HttpGet; 
    import org.apache.http.impl.client.BasicResponseHandler; 
    import org.apache.http.impl.client.DefaultHttpClient; 

public class Main { 

public final static void main(String[] args) throws Exception { 

    HttpClient httpclient = new DefaultHttpClient(); 
    try { 
     HttpGet httpget = new HttpGet("http://www.google.com/"); 

     System.out.println("executing request " + httpget.getURI()); 

     // Create a response handler 
     ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
     String responseBody = **httpclient.execute(httpget, responseHandler);** 
     System.out.println("----------------------------------------"); 
     System.out.println(responseBody); 
     System.out.println("----------------------------------------"); 

    } finally { 
     // When HttpClient instance is no longer needed, 
     // shut down the connection manager to ensure 
     // immediate deallocation of all system resources 
     httpclient.getConnectionManager().shutdown(); 
    } 
} 

}

的错误是 “httpclient.execute(HTTPGET,ResponseHandler所);” IT说它找不到方法执行(HttpGet,ResponseHandler) 这个问题不应该是这个例子的工作吗?我究竟做错了什么?! :S

回答

0

我也得到了同样的错误。我通过添加“httpcore-4.2.1.jar”来解决它。然后它开始抱怨没有找到用于记录的Class Def。所以我添加了“commons-logging-1.1.1.jar”,现在我认为它工作正常。这两个文件都可以与“httpclient-4.2.1.jar”一起找到。

希望这会有所帮助。

相关问题