Passing username and password using LWP::UserAgent
Passing username and password using LWP::UserAgent
am 11.12.2006 10:40:57 von Kill Bill
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'] => '');
$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..
Re: Passing username and password using LWP::UserAgent
am 11.12.2006 15:00:17 von Gunnar Hjalmarsson
neo wrote:
> Hi,
> I ve written a perl script which sends the user name and password
> through a proxy for authentication,the problem is that
.... you multi-posted, which isn't appreciated on Usenet.
http://lipas.uwasa.fi/~ts/http/crospost.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Passing username and password using LWP::UserAgent
am 12.12.2006 02:34:28 von Big and Blue
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.
Re: Passing username and password using LWP::UserAgent
am 12.12.2006 04:50:18 von Kill Bill
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.
Re: Passing username and password using LWP::UserAgent
am 12.12.2006 17:09:26 von keith
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'] => '');
>
> $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..
Re: Passing username and password using LWP::UserAgent
am 13.12.2006 02:36:39 von Big and Blue
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.