I'm trying to write  a simple code which uses perl LWP package and retrieves
content from a protected URL. It works fine for URL without protection, but
for the URL, where I've to enter userid and password, it is not working.

Attached is the code. Appreciate any input/example code to do this.

Thanks in advance.

------------------------------
# Build a UserAgent
  my $browser = 'Mozilla/4.04 [en] (WinNT; I)'; #??
  my $user   = 'iweb';
  my $passwd = 'iweb123';
  my $timeout = 30;
  my $ua = new LWP::UserAgent;
  #$ua->proxy('http', 'http://proxy.wan.gs.com:82'); #??
  $ua->timeout($timeout);
  
  # Create an HTTP request object
  my $webroot = "http://localhost/";
 my $url  = $webroot . $file;
 #my $url   = "http://wwwsamdev.gsam.gs.com/TKPUB/EMAILTEST/try.html";
#Works
  my $url   =
"http://wwwsamdev.gsam.gs.com/instamgdoc/investstr/invstra.html"; # needs
Auth
  my $req = new HTTP::Request('GET', $url );
  my $content_type;

  if ( $doc_type eq  'html' ) {
          $content_type= 'text/html';
  }
  elsif ( $doc_type eq  'pdf' ) {
        $content_type= 'application/pdf'; 
  } 
  
  #print "URL: $url, ConType: $content_type\n";

use MIME::Base64;
$encoded = encode_base64('u_id:passwd');

  $req-> header('Content-type' => $content_type );
  $req->header('User-Agent' =>  $browser);
  $req->header('Authorization_basic' =>$encoded  );

  my $newresp = $ua->request($req);
  my $content = "";
  
  if ($newresp->is_success)
  {
      $content = $newresp->content;
      $content =~ s/\r\n/\n/g;
      $content =~ s/\r/\n/g;
      #print $content;
  }
  else
  {
      die "$0: error " . status_message($newresp->code);
  }
  return $content;
}  
          -Tapas 

_______________________
Tapas Banerjee
Investment Management Division(E-Commerce Group)
Goldman Sachs, 32 Old Slip, New York - 10004
212-357-0390
[EMAIL PROTECTED]

Reply via email to