LWP - Get a url which is redirected

How do I fetch a document if the url redirects to another site for authentication and then redirects back to it?

In this case, how do I sign in onto a redirected website, and fetch the document of the provided link when authorization succeeded and brought back to the target link?

Thanks,
CJ
CaitlinJAsked:
Who is Participating?
 
sosolalaConnect With a Mentor Commented:
Find out the url that opens in the popupbox but if you mean a https popupbox you could use something like:


sub check_order {
        #check for an open order  (critical!!)
        my $req = new HTTP::Request 'POST','https://investment.datek.com/dummy.htm';
        $req->content_type('application/x-www-form-urlencoded');
        my $chx = "REPORT  ";
        my $action = "order";
        $req->content("ropen&name=$action&userid=$efusername&__chx=$chx");
        $req->authorization_basic($username,$passwd);
        $ua->agent("Mozilla/4.73 ");
        my $res = $ua->request($req);
        unless ($res->code eq "200") { return "URLERROR $res->code";  }
        my @stuff = split "\n", $res->as_string;

        #extract needed data:
0
 
sosolalaCommented:
Depence on the autentication methode

you are asking for a very technical answer

but your question doesn;t contain any technical methode

but If you can do it in a browser you can script it


Most probally you have to perseve the cookie.
in you script...
Gtz
0
 
SegFaultCommented:
If the method is using cookies, you can use the CookieJar module, which plugs into LWP.

I had just this situation, however, the CookieJar was using version 2.0 of cookies and the site wanted version 1.0, so I had to break out etherreal and sniff the packets.  It was a hack job, but it worked.

Take a look at the documentation for implementing a cookiejar.

If the site is not using cookies, we'd need to know specifically what authentication mechanism is being used.  If you can provide some amplifying information, it would help.

seg
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sosolalaCommented:
Below a sample script that logs in to yahoo
to login to a second site...add under the coresponding  
$req2 that looks like the $req pointing to a second site
$res2 that looks like the $res contains then the second html

this way you can login to 2 sites..and use the same cookie.
now sometimes you have a box that that pops up requesting the login and passwd...

Then there is a different autentication methode..needed
used let me know and I post it :-) hope this will answer you question.!

#!/usr/bin/perl

my login = "loginname";
my passwd = "passwrd";

use LWP::UserAgent;
  use HTTP::Cookies;

  $ua = LWP::UserAgent->new;
  $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt",
                                     autosave => 1));

  $ua->agent("$0/0.1 " . $ua->agent);
  # $ua->agent("Mozilla/8.0") # pretend we are very capable browser

  $req = HTTP::Request->new(GET => 'http://login.yahoo.com/config/login?login=$login&passwd=$passwd&.src=quote&.done=http://finance.yahoo.com');
  $req->header('Accept' => 'text/html');

  # send request
  $res = $ua->request($req);

  # check the outcome
  if ($res->is_success) {
     #print $res->content;
  } else {
     print "Error: " . $res->status_line . "\n";
  }

0
 
CaitlinJAuthor Commented:
so what if you have a pop up box requesting a login and password?

and it's an https site as well (using SSL authentication)

Thanks for all the tips, but I still have problem logging onto the site...

CJ
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 7 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by sosolala.

Please post any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.