2011-11-03 4 views
0

나는 이것을 해결하기 위해 열심히 노력했지만 나는 할 수 없었다. 아파치에서 httpClient 4.1.2를 사용하려고합니다. 이 예제로 시작한 논리로서, 문제는 제가 이해하지 못하는 이상한 오류가 있다는 것입니다. 이 거래입니다 :ClientWithResponseHandler 예제 오류가 발생 했습니까?

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"를 추가하여이 문제를 해결했습니다. 그런 다음 클래스 Def가 로깅되지 않았다고 불평하기 시작했습니다. 그래서 "commons-logging-1.1.1.jar"을 추가했는데 이제는 정상적으로 작동한다고 생각합니다. 두 파일은 "httpclient-4.2.1.jar"과 함께 찾을 수 있습니다.

희망이 도움이됩니다.