Click here to get back home

Passing username and password using LWP::UserAgent

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Passing username and password using LWP::UserAgent kill bill 12-11-2006
Posted by kill bill on December 11, 2006, 4:40 am
Please log in for more thread options


Hi,
I ve written a perl script which sends the user name and password
through a proxy for authentication,the problem is that after it is
getting authenticated it is not showing the contents of the desired
page i.e the page which the user wants to visit is not being displayed

code

use LWP::UserAgent;

$ua = new LWP::UserAgent;

$ua->proxy(['http'] => '<http://abc.com:389>');

$req = new HTTP::Request 'GET','http://xyz.com';

$req->proxy_authorization_basic('username','password');

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

print $res->content if $res->is_success;
print $ua->request($req)->as_string;

code

the problem with the above code is that it does not directs the user to
'http://xyz.com" after authentication can anybody help me out please..


Posted by Big and Blue on December 11, 2006, 8:34 pm
Please log in for more thread options


kill bill wrote:

>
> the problem with the above code [snipped] is that it does not directs the user
to
> 'http://xyz.com" after authentication can anybody help me out please..

How do you know that authentication has occurred?

The code wouldn't "direct". IIRC it would (should) send a request
*including authentication* to the proxy and so you'd only send one request.
There are also 2 ways of contacting proxies, GETs and CONNECTs, and some
proxies will only handle the latter (from memory...).

Could you provide some more information about what leads you to make your
statements?


--
Just because I've written it doesn't mean that
either you or I have to believe it.

Posted by kill bill on December 11, 2006, 10:50 pm
Please log in for more thread options


Hi Big and Blue,

Thanks for your reply.


When i used d statements:-

if ($res->is_error)
{
print "error";
}

in the code it did not print error and all the more I even tried d
following statements to be very sure:-

if ($res->is_success)
{
print"success";
}

and it gave output as "success" which even validates my point.
Big and Blue wrote:
> kill bill wrote:
>
> >
> > the problem with the above code [snipped] is that it does not directs the
user to
> > 'http://xyz.com" after authentication can anybody help me out please..
>
> How do you know that authentication has occurred?
>
> The code wouldn't "direct". IIRC it would (should) send a request
> *including authentication* to the proxy and so you'd only send one request.
> There are also 2 ways of contacting proxies, GETs and CONNECTs, and some
> proxies will only handle the latter (from memory...).
>
> Could you provide some more information about what leads you to make your
> statements?
>
>
> --
> Just because I've written it doesn't mean that
> either you or I have to believe it.


Posted by Big and Blue on December 12, 2006, 8:36 pm
Please log in for more thread options


kill bill wrote:
>
> When i used d statements:-
>
> if ($res->is_error)
> {
> print "error";
> }
>
> in the code it did not print error
>...

But, from what I read, it didn't get any real output either, so I was
querying why you interpreted that as authentication having worked. I'd
start by assuming that *nothing* is working...

If you can, have a look at actual network traffic (snoop. ethereal,
wireshark, ....) to see what is going on.

And see Keith's comment about the proxy setting in your script.

--
Just because I've written it doesn't mean that
either you or I have to believe it.

Posted by Keith on December 12, 2006, 11:09 am
Please log in for more thread options


I have very similar code, which is working.

One difference is that I am not using the
diamond operator to read from the proxy
page (which I'm not sure works?). I have a
line like:

$ua->proxy('http','http://myProx:myPort/proxy.pac');

What happens when you point your browser to the two
URL's (the proxy page and the GET page); do you get
what you expect?

Can you set an environment / shell variable and do a wget (*nix) or
GET (DOS)?

Keith



kill bill wrote:
> Hi,
> I ve written a perl script which sends the user name and password
> through a proxy for authentication,the problem is that after it is
> getting authenticated it is not showing the contents of the desired
> page i.e the page which the user wants to visit is not being displayed
>
> code
>
> use LWP::UserAgent;
>
> $ua = new LWP::UserAgent;
>
> $ua->proxy(['http'] => '<http://abc.com:389>');
>
> $req = new HTTP::Request 'GET','http://xyz.com';
>
> $req->proxy_authorization_basic('username','password');
>
> $res = $ua->request($req);
>
> print $res->content if $res->is_success;
> print $ua->request($req)->as_string;
>
> code
>
> the problem with the above code is that it does not directs the user to
> 'http://xyz.com" after authentication can anybody help me out please..


Similar ThreadsPosted
password in SFTP::Foreign August 23, 2007, 11:48 am
Free Random Password Generator January 26, 2005, 10:09 pm
[DBI][Oracle] providing login/password, but having ORA-01004 November 15, 2004, 9:44 am
checking userid and password against windows domain (Active directory) June 9, 2005, 10:57 am
username passwd expect September 14, 2006, 12:36 am
Determine NT domain username of web client February 3, 2005, 4:24 pm
Looking for module that will expands domain/username to email address October 23, 2004, 12:56 am
Net::SSH::Perl dies during logon only when username is entered in stdin November 5, 2004, 3:37 pm
Passing a DBI connection between [Unix] processes January 7, 2005, 1:01 pm
Options for passing Hash to a subroutine. March 30, 2005, 7:39 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap