//Création d'une instance de HttpClient
HttpClient client = new HttpClient();
//Création d'une méthode POST
PostMethod method = new PostMethod("http://localhost/monAppli/login_page.php");
//On défini les variables
try {
NameValuePair[] data = {
new NameValuePair("user", "administrator"),
new NameValuePair("pwd", "")
};
method.setRequestBody(data);
client.executeMethod(method);
String response = new String(method.getResponseBodyAsString().getBytes("8859_1"));
System.out.println("Affichage de la réponse");
System.out.println(response);
method.releaseConnection();
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
System.out.println("Fermeture de la connection");
// La connection est lâché.
method.releaseConnection();
}
Partager