IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Modules Perl Discussion :

Besoin de s'authentifier avec NET::HTTP + IIS NTLM


Sujet :

Modules Perl

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5
    Points : 1
    Points
    1
    Par défaut Besoin de s'authentifier avec NET::HTTP + IIS NTLM
    Bonjour,

    Je veux me connecter à un site, mais celui ci n'accepte pas les connections anonymes tel que :
    Je voudrai prendre le user qui lance le script ? est ce possible


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    my $serveur = "www.serveur.com";
    my $repertoire_virtuel = "/dirvir";
     
    my $s = Net::HTTP->new(Host => $serveur) || die "Erreur : $@";
    $s->write_request(GET => "$repertoire_virtuel/acceuil.asp", 'User-Agent' => "Mozilla/5.0");
     
    my($code, $mess, %h) = $s->read_response_headers;
     
    my $buf;
    my $n;
    for ($n = $s->read_entity_body ($buf, 1024); $n != 0 ;$n = $s->read_entity_body ($buf, 1024))
    { 
    print $buf;
    #print "\n\n\ $buf \n\n";
    Merci pour votre aide

    Ajout des balises [ code ] et [ /code ] par 2Eurocents

  2. #2
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    Pas très clair...
    S'agit-il d'un site web sécurisé, employant https ?
    Dans ce cas je vous conseille d'utiliser plutôt LWP et Net::SSL.
    Sinon, LWP permet aussi de prendre en charge d'autre mode d'identification.

    --
    Jedaï

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Quand je me connect par ce script une page je recolte une erreur http 401.

    Il ne sagit pas de https.

    Je suis novice en prog en general, pouvez vous m'indiquer où trouver de la doc comprehensible ( si possivble en français )

    Comment faire pour seulement specifier un utilisateur et ou un pw à cette commande ?

  4. #4
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    Ok, la page LWP spécifie qu'il prend en charge les erreurs 401 par le biais de LWP::Authen::Basic et dans lwpcook on trouve :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    ACCESS TO PROTECTED DOCUMENTS
     
    Documents protected by basic authorization can easily be accessed like this:
     
      use LWP::UserAgent;
      $ua = LWP::UserAgent->new;
      $req = HTTP::Request->new(GET => 'http://www.linpro.no/secret/');
      $req->authorization_basic('aas', 'mypassword');
      print $ua->request($req)->as_string;
     
    The other alternative is to provide a subclass of LWP::UserAgent that overrides the get_basic_credentials() method. Study the lwp-request program for an example of this.
    Tous ces modules font partie du Core et tu peux accéder à lwpcook par le biais de "perldoc lwpcook" dans un shell quelconque ou dans la doc ActivePerl si tu es sous Windows.

    --
    Jedaï

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Ca marche merci beaucoups !! :-)

  6. #6
    Membre expert
    Avatar de 2Eurocents
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    2 177
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 2 177
    Points : 3 166
    Points
    3 166
    Par défaut
    Alors il ne faut pas oublier d'ajouter le tag [Résolu], sur le sujet, en partant

    Bonne continuation
    La FAQ Perl est par ici
    : La fonction "Rechercher", on aurait dû la nommer "Retrouver" - essayez et vous verrez pourquoi !

  7. #7
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5
    Points : 1
    Points
    1
    Par défaut IIS et NTLM
    Malheureusement, la connexion marchait bien mais le profile des useurs ont changé, maintenant le NTLM me bloque

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    HTTP/1.1 401 (Unauthorized) Access Denied 
    Date: Tue, 26 Jul 2005 14:08:43 GMT 
    Server: Microsoft-IIS/5.0 
    WWW-Authenticate: Negotiate 
    WWW-Authenticate: NTLM 
    Content-Length: 4431 
    Content-Type: text/html 
    Content-Type: text-html; charset=Windows-1252 
    Client-Date: Tue, 26 Jul 2005 14:08:43 GMT 
    Client-Peer: 192.92.123.78:80 
    Client-Warning: Unsupported authentication scheme 'ntlm' 
    Title: You are not authorized to view this page 
    X-Meta-ROBOTS: NOINDEX

    Client-Warning: Unsupported authentication scheme 'ntlm'

    Pouvez vous m'aider à déméler ce mic mac ?

  8. #8
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    Visiblement, le protocole d'identification a changé... Essaie d'autres méthodes. Comme je ne sais pas quel est le protocole employé, je ne peux pas vraiment t'aider plus... Fais le tour des modules LWP::Authen::*.

    --
    Jedaï

  9. #9
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Plus d'infos
    Le code integral + bebug :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    use LWP::UserAgent;
    use LWP::Debug qw(+);
    require 'C:\newperl\HTTP.pm';
    require 'C:\newperl\Methods.pm';
      $ua = LWP::UserAgent->new;
      $req = HTTP::Request->new(GET => 'http://www.monserveur.com/page.asp');
      $req->authorization_basic('DOMAINE\USER', 'passwd');
      print $ua->request($req)->as_string;
    le resultat :

    LWP::UserAgent::new: ()
    LWP::UserAgent::request: ()
    LWP::UserAgent::simple_request: GET http://www.monserveur.com/page.asp
    LWP::UserAgent::_need_proxy: Not proxied
    LWP:rotocol::http::request: ()
    LWP:rotocol::http::request: GET /page.asp HTTP/1.0
    Authorization: Basic SU5FVFBTQVxNWlBOUFIwMDpiZGZobHA0OA==
    Host: www.monserveur.com
    User-Agent: libwww-perl/5.51

    LWP:rotocol::http::request: reading response
    LWP:rotocol::http::request: HTTP/1.1 401 Access Denied
    Server: Microsoft-IIS/5.0
    Date: Wed, 27 Jul 2005 10:20:53 GMT
    WWW-Authenticate: Negotiate
    WWW-Authenticate: NTLM
    Content-Length: 4431
    Content-Type: text/html

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    Est ce que ca t'inspire ?

  10. #10
    Expert éminent
    Avatar de Jedai
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2003
    Messages
    6 245
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2003
    Messages : 6 245
    Points : 8 586
    Points
    8 586
    Par défaut
    Essaie la méthode "credentials" de LWP::UserAgent :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
     
    HTTP Authentication
     
    Many web sites restrict access to documents by using ``HTTP Authentication''. This isn't just any form of ``enter your password'' restriction, but is a specific mechanism where the HTTP server sends the browser an HTTP code that says ``That document is part of a protected 'realm', and you can access it only if you re-request it and add some special authorization headers to your request''.
     
    For example, the Unicode.org admins stop email-harvesting bots from harvesting the contents of their mailing list archives, by protecting them with HTTP Authentication, and then publicly stating the username and password (at http://www.unicode.org/mail-arch/) -- namely username ``unicode-ml'' and password ``unicode''.
     
    For example, consider this URL, which is part of the protected area of the web site:
     
      http://www.unicode.org/mail-arch/unicode-ml/y2002-m08/0067.html
     
    If you access that with a browser, you'll get a prompt like ``Enter username and password for 'Unicode-MailList-Archives' at server 'www.unicode.org'''.
     
    In LWP, if you just request that URL, like this:
     
      use LWP;
      my $browser = LWP::UserAgent->new;
     
      my $url =
       'http://www.unicode.org/mail-arch/unicode-ml/y2002-m08/0067.html';
      my $response = $browser->get($url);
     
      die "Error: ", $response->header('WWW-Authenticate') || 'Error accessing',
        #  ('WWW-Authenticate' is the realm-name)
        "\n ", $response->status_line, "\n at $url\n Aborting"
       unless $response->is_success;
     
    Then you'll get this error:
     
      Error: Basic realm="Unicode-MailList-Archives"
       401 Authorization Required
       at http://www.unicode.org/mail-arch/unicode-ml/y2002-m08/0067.html
       Aborting at auth1.pl line 9.  [or wherever]
     
    ...because the $browser doesn't know any the username and password for that realm (``Unicode-MailList-Archives'') at that host (``www.unicode.org''). The simplest way to let the browser know about this is to use the credentials method to let it know about a username and password that it can try using for that realm at that host. The syntax is:
     
      $browser->credentials(
        'servername:portnumber',
        'realm-name',
       'username' => 'password'
      );
     
    In most cases, the port number is 80, the default TCP/IP port for HTTP; and you usually call the credentials method before you make any requests. For example:
     
      $browser->credentials(
        'reports.mybazouki.com:80',
        'web_server_usage_reports',
        'plinky' => 'banjo123'
      );
     
    So if we add the following to the program above, right after the < $browser = LWP::UserAgent-new; >> line...
     
      $browser->credentials(  # add this to our $browser 's "key ring"
        'www.unicode.org:80',
        'Unicode-MailList-Archives',
        'unicode-ml' => 'unicode'
      );
     
    ...then when we run it, the request succeeds, instead of causing the die to be called.
    Bonne chance.

    --
    Jedaï

Discussions similaires

  1. [Débutant] Aide: authentification AD avec asp.net et iis
    Par Skloug dans le forum ASP.NET
    Réponses: 1
    Dernier message: 19/01/2015, 09h27
  2. chargement d'archive avec net/http
    Par beusse dans le forum Ruby
    Réponses: 2
    Dernier message: 13/07/2011, 08h29
  3. Besoin d'aide avec Net::HTTP
    Par scaleo dans le forum Modules
    Réponses: 2
    Dernier message: 28/01/2007, 17h12
  4. Besoin d'aide avec Net::Server::Multiplex
    Par cryptorchild dans le forum Modules
    Réponses: 1
    Dernier message: 20/07/2006, 06h47
  5. problème avec net::http
    Par piotr dans le forum Modules
    Réponses: 3
    Dernier message: 20/03/2006, 10h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo