Bonjour, j’ai trouvé un code ici : http://www.exampledepot.com/egs/java.net/auth.html mais il me renvoie la même page quel que soit le mot de passe, correct ou non.
[code]Code :
import java.io.;
import java.net.;
public class chot {
/**
-
@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// Install the custom authenticator
Authenticator.setDefault(new MyAuthenticator());
// Access the page
try {
// Create a URL for the desired page
URL url = new URL(“https://www.creditmutuel.fr/cmne/fr/banque/situation_financiere.cgi” );
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
}
import java.net.Authenticator;
import java.net.InetAddress;
import java.net.PasswordAuthentication;
public class MyAuthenticator extends Authenticator {
// This method is called when a password-protected URL is accessed
protected PasswordAuthentication getPasswordAuthentication() {
// Get information about the request
String promptString = getRequestingPrompt();
String hostname = getRequestingHost();
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();
// Get the username from the user…
String username = “0290012345678”;
// Get the password from the user…
String password = “87654321”;
// Return the information
return new PasswordAuthentication(username, password.toCharArray());
}
}[/code]
Pouvez-vous me dire pourquoi ?