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 50 51 52 53
| public void connexionPage(int methode) {
HttpResponse reponse = null;
if (methode == POST) {
HttpPost httpost = new HttpPost(this.url);
HttpContext localContext = new BasicHttpContext();
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
for(Info inf : this.listeInfo){
nvps.add(new BasicNameValuePair(inf.getName(), inf.getValue()));
}
System.out.println("Connecting to : "+this.url);
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
reponse = this.httpClient.execute(httpost,localContext);
System.out.println(reponse.getStatusLine().toString());
Header locationHeader[] = reponse.getHeaders("location");
for(int i=0;i<locationHeader.length;i++){
System.out.println("loc "+i+" "+locationHeader[i]);
}
Header header[] = reponse.getAllHeaders();
for(int i=0;i<header.length;i++){
System.out.println(i+" "+header[i]);
}
if(locationHeader.length==1){
reponse.getEntity().consumeContent();
HttpGet httpGet = new HttpGet(locationHeader[0].getValue());
reponse = this.httpClient.execute(httpGet);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
InputStream data = null;
try {
data = reponse.getEntity().getContent();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
this.assemblageDonnees(data);
listeCookies = this.httpClient.getCookieStore().getCookies();
}
} |
Partager