Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1720 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  charger une page html avec id/passwrd

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

charger une page html avec id/passwrd

n°2128573
sespille
Posté le 27-02-2012 à 20:13:01  profilanswer
 

bonjour, je croyais avoir trouvé mon bonheur, mais la page retournée est la même avec le bon ou le mauvais mot de passe.
Ce code vient de là je crois http://www.exampledepot.com/egs/java.net/auth.html

Code :
  1. import java.io.*;
  2. import java.net.*;
  3. public class chot {
  4. /**
  5.  * @param args
  6.  */
  7. public static void main(String[] args) {
  8.  // TODO Auto-generated method stub
  9.  // Install the custom authenticator
  10.  Authenticator.setDefault(new MyAuthenticator());
  11.  // Access the page
  12.  try {
  13.      // Create a URL for the desired page
  14.      URL url = new URL("https://www.creditmutuel.fr/cmne/fr/banque/situation_financiere.cgi" );
  15.      // Read all the text returned by the server
  16.      BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  17.      String str;
  18.      while ((str = in.readLine()) != null) {
  19.          System.out.println(str);
  20.          // str is one line of text; readLine() strips the newline character(s)
  21.      }
  22.      in.close();
  23.  } catch (MalformedURLException e) {
  24.  } catch (IOException e) {
  25.  }
  26.  }
  27. }
  28. import java.net.Authenticator;
  29. import java.net.InetAddress;
  30. import java.net.PasswordAuthentication;
  31. public class MyAuthenticator extends Authenticator {
  32.     // This method is called when a password-protected URL is accessed
  33.     protected PasswordAuthentication getPasswordAuthentication() {
  34.         // Get information about the request
  35.         String promptString = getRequestingPrompt();
  36.         String hostname = getRequestingHost();
  37.         InetAddress ipaddr = getRequestingSite();
  38.         int port = getRequestingPort();
  39.         // Get the username from the user...
  40.         String username = "0290012345678";
  41.         // Get the password from the user...
  42.         String password = "87654321";
  43.         // Return the information
  44.         return new PasswordAuthentication(username, password.toCharArray());
  45.     }
  46. }


 
Merci de votre aide.

mood
Publicité
Posté le 27-02-2012 à 20:13:01  profilanswer
 

n°2139048
sespille
Posté le 25-04-2012 à 16:13:59  profilanswer
 

Le code a bien changé (POST, cookie, SSL) mais ça marche toujours pas (page d'identification retournée)

Code :
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStreamWriter;
  8. import java.io.PrintWriter;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11. import javax.net.ssl.HttpsURLConnection;
  12. public class cook {
  13. public static void main(String args[]) throws IOException{
  14.    
  15.  URL url = new URL("https://www.creditmutuel.fr/cmne/fr/identification/default.cgi" );
  16.  HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
  17.     try {
  18.    
  19.  // envoi POST
  20.    
  21.      String cookie = uc.getHeaderField(8);
  22.      cookie = cookie.substring(0, cookie.indexOf(";" ));
  23.   System.out.println(cookie);
  24.   uc = (HttpsURLConnection) url.openConnection();
  25.      uc.setDoOutput(true);
  26.      uc.setRequestProperty("method","POST" );
  27.   uc.addRequestProperty("Cookie", cookie);
  28.   uc.addRequestProperty("Content-type","application/x-www-form-urlencoded" );
  29.      PrintWriter pout = new PrintWriter( new OutputStreamWriter(
  30.       uc.getOutputStream(), "iso-8859-1" ), true );
  31.      pout.print("_cm_user=0290012345678&_cm_pwd=87654321&_cm_app=SITFIN&_cm_langue=fr" );
  32.      pout.flush();
  33.    
  34. // lecture réponse  
  35.    
  36.      uc = (HttpsURLConnection) url.openConnection();
  37.      uc.setRequestProperty("Cookie", cookie);
  38.      File fichier = new File("/home/eric/Bureau/extrait" ) ;
  39.      BufferedWriter ecr = new BufferedWriter (new FileWriter (fichier));
  40.      BufferedReader lit =new BufferedReader(new InputStreamReader(uc.getInputStream()));    
  41.      System.out.println ("début" );
  42.      if (! fichier.exists()) fichier.createNewFile();
  43.      do{
  44.       String ligne=lit.readLine();
  45.       if(ligne==null)break;
  46.       ecr.write(ligne);
  47.      } while(true);
  48.      System.out.println ("fin" );
  49.    
  50.      lit.close(); ecr.close(); pout.close(); uc.disconnect();
  51.      
  52.    
  53.     } catch (MalformedURLException e) {
  54.       System.out.println("1 "+e);     // bad postURL
  55.     } catch (IOException e2) {
  56.       System.out.println("2 "+e2);    // I/O error
  57.     }
  58. }
  59. }


Message édité par sespille le 25-04-2012 à 16:43:33
n°2142947
gynoide
Posté le 19-05-2012 à 01:44:09  profilanswer
 

Salut,

 

Quel est ton souci ?

n°2143604
sespille
Posté le 24-05-2012 à 22:43:46  profilanswer
 

Bonjour gynoide, merci de te pencher sur mon problème :
 
A terme, je voudrais faire un programme Java qui va sur le site de ma banque pour demander un n° de carte virtuelle. Pour commencer par du plus simple (c'est un objectif que je me suis fixé pour progresser, je sais qu'il existe des solutions toutes faites), je cherche à obtenir mon solde bancaire.
 
Beaucoup d'approximations jalonnent mon code et je tâtonne depuis un moment.
 
Ce que je crois comprendre :
 
- j'ouvre une connexion httpsurlconnection (sécurisée) à la page d'identification https://www.creditmutuel.fr/cmne/fr [...] efault.cgi
- je récupère le cookie de session dans l'en-tête
- j'envoie mon mot de passe et mon identifiant en POST, en spécifiant un navigateur autorisé et d'autres choses (...?)
- je ferme la connexion pour la réouvrir (que la CGI produise ma page SITFIN, situation financière)
 
Mais c'est la page d'identification que je retrouve.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  charger une page html avec id/passwrd

 

Sujets relatifs
Ordre de chargement des éléments d'une page webAdaptation auto. Page Web / Résolution
[HTML] Lancement d'une applicationAide HTML structure de page
Réactualisation automatique page htmlProbleme Prototype Affichage Page
[html] Chargement rapide d'un background lourd 
Plus de sujets relatifs à : charger une page html avec id/passwrd


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR