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
|
public void Connect(String psd, String mdp) throws Exception, URISyntaxException, ClientProtocolException, IOException{
URI uri = new URI(adress);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(uri);
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
ArrayList <BasicNameValuePair> nvps = new ArrayList <BasicNameValuePair>();
nvps.add(new BasicNameValuePair("psd", psd));
nvps.add(new BasicNameValuePair("mdp", mdp));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
System.out.println("Post logon cookies:");
ArrayList<Cookie> cookies = (ArrayList<Cookie>) httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
httpclient.getConnectionManager().shutdown();
} |
Partager