in reply to Re^5: WWW::Mechanize Problem
in thread WWW::Mechanize Problem

Is there any way of making my code work.

I have given the code below
#!C:/Perl/bin/perl.exe use LWP::Simple; use LWP::UserAgent; use HTTP::Request; use HTTP::Response; use HTML::LinkExtor; use LWP::Authen::Ntlm; my $URL= "http://eonet.level3.com/"; $browser = LWP::UserAgent->new(); $browser->timeout(10); my $request = HTTP::Request->new(GET => $URL); my $response = $browser->request($request); if ($response->is_error()) {printf "%s\n", $response->status_line;} $contents = $response->content(); #print $contents; print $response->status_line(), "\n"; print $response->headers()->as_string();
Please help!!!

Replies are listed 'Best First'.
Re^7: WWW::Mechanize Problem
by ikegami (Patriarch) on Apr 07, 2009 at 18:42 UTC
      Hi ikegami (Cardinal) and all Monks,

      I finally got the code to work. Thanks for your valuable suggestions.

      But i have a new problem now that i cannot acces web pages ending with .aspx extn instead of .html or .com extns.
      I have given my code below:
      #!C:/perl/bin/perl.exe use LWP::UserAgent; use HTTP::Request::Common; my $url= 'http://goweb.corp.global.level3.com/sites/ti_nm/tni/default. +aspx'; my $ua = new LWP::UserAgent(keep_alive => 1); $ua->credentials('goweb.corp.global.level3.com/sites/ti_nm/tni/default +.aspx:80','',"LEVEL3\\username",'password'); $request = GET $url; print "--Performing request now...------------------\n"; $response = $ua->request($request); print "--Done with request---------------------------\n"; if ($response -> is_success) { print "It worked!->". $response->code. "\n"; } else { print "It didn't work!->". $response->code. "\n"; } $contents = $response -> content(); #print "$contents\n"; open(FH,">C:/eonet.html"); print FH $contents; close FH; print $response->status_line(), "\n"; print $response->headers()->as_string();
      I am pasting my result as well for your reference
      --Performing request now...------------------ --Done with request--------------------------- It didn't work!->401 401 Unauthorized Date: Wed, 08 Apr 2009 18:02:59 GMT Server: Microsoft-IIS/6.0 WWW-Authenticate: NTLM Content-Length: 1656 Content-Type: text/html Content-Type: text/html; charset=Windows-1252 Client-Date: Wed, 08 Apr 2009 18:02:59 GMT Client-Peer: 10.1.158.205:80 Client-Response-Num: 1 MicrosoftSharePointTeamServices: 6.0.2.5530 Title: You are not authorized to view this page X-Powered-By: ASP.NET
      Please review this and provide your comments!!! Thanks in advance

        Hi ikegami (Cardinal) and all Monks,

        .oO( I'd rather be a Chickadee )

        From the docs for credentials

        The $netloc is a string of the form "<host>:<port>".

        Instead of
        $ua->credentials('goweb.corp.global.level3.com/sites/ti_nm/tni/default +.aspx:80', ...);
        you should be using
        $ua->credentials('goweb.corp.global.level3.com:80', ...);

        That sets the user/passwd for all requests to that server, including http://goweb.corp.global.level3.com/sites/ti_nm/tni/default.aspx.