Accès aux URLs sécurisés: Comment s’authentifier avec java.net.Authenticator.getRequestingPrompt()

Author:

 url, méthode, adresse, set, url, authentification, java
{filelink=8984}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.InetAddress;
import java.net.PasswordAuthentication;
import java.net.URL;

public class URLAuteh
{
  public static void main(String[] argv) throws Exception
  	{

  	 // Exécuter cette méthode si le lien nécessite une authentification
    Authenticator.setDefault(new Authenticator()
    	 {

  protected PasswordAuthentication getPasswordAuthentication() {
    String prompt = getRequestingPrompt();
    System.out.println(prompt);
    String host = getRequestingHost();
    System.out.println(host);
    InetAddress adresseIP = getRequestingSite();
    System.out.println(adresseIP);
    int port = getRequestingPort();
    System.out.println (port);

    String username = "nom d'utilisateur";
    String password = "mot_de_passe******";
    return new PasswordAuthentication(username, password.toCharArray());
  }
});

    URL url = new URL("http://www.exemples.com:80/membreLogin.php");

    // Accéder au contenu de l'URl et l'afficher
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

    String str;
    while ((str = in.readLine()) != null) {
      System.out.println(str);
    }
    in.close();

  }
}

A Voir sur le même Sujet:

  • java lire contenu url
  • executer une url avec authentification en java
  • java tester url avec authentification
  • authentification avec java
  • s'authentifier a un site avec socket java
  • comment faire authentification en java
  • comment enlever authentification obligatoire de JAVA
  • pb java authentification obligatoire
  • exemple authentification avec java
  • java 6 http authenticator.setdefault

Leave a Reply

Your email address will not be published. Required fields are marked *