Bonjour,

je voudrais utiliser HttpClient (Api de la fondation Apache destinée aux flux internet/http) avec Eclipse, mais je me heurte a un probleme.

Je l'ajoute au build path etc... de mon projet, le tout compile tres bien, voice le code, qui n'est autre que le "sample code" du site officiel :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
import java.io.IOException;
 
import org.apache.commons.httpclient.DefaultMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
 
public class Main {
 
  private static String url = "<URL>";
 
  public static void main(String[] args) {
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();
 
    // Create a method instance.
    GetMethod method = new GetMethod(url);
 
    // Provide custom retry handler is necessary
    DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();
    retryhandler.setRequestSentRetryEnabled(false);
    retryhandler.setRetryCount(3);
    method.setMethodRetryHandler(retryhandler);
 
    try {
      // Execute the method.
      int statusCode = client.executeMethod(method);
 
      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }
 
      // Read the response body.
      byte[] responseBody = method.getResponseBody();
 
      // Deal with the response.
      // Use caution: ensure correct character encoding and is not binary data
      System.out.println(new String(responseBody));
 
    } catch (IOException e) {
      System.err.println("Failed to download file.");
      e.printStackTrace();
    } finally {
      // Release the connection.
      method.releaseConnection();
    }
  }
}
Le tout compile, mais a l'éxécution j'ai droit à un:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
	at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:69)
	at Main.main(Main.java:14)
Si vous avez une idée...