Click here to get back home

LWP Problems (Authentication?)

 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
LWP Problems (Authentication?) Jason Keirstead 09-05-2004
Posted by Jason Keirstead on September 5, 2004, 7:12 am
Please log in for more thread options
I am having problems getting LWP to post data to a URL that requires
authentication. Here is the syntax I am using:

my $ua = LWP::UserAgent->new(timeout => 1800);
$ua->credentials("localhost:80", "Identification", "user",
"password");

my $response = $ua->request(
POST 'http://localhost/some/cgi',
Content_Type => 'application/x-www-form-urlencoded',
Content => 'foo=bar',
);

print $response->as_string unless $response->is_success;

With every request I am getting:

Content-Type: text/plain
Client-Date: Sun, 05 Sep 2004 13:08:55 GMT
Client-Warning: Internal response

500 read timeout

But if I do the reuqest myself, with the exact same URL, it works
fine, so it is not my local CGI.

What am I doing wrong? Is there any way to enable some debug flag so I
can see more of what LWP is doing (the auth headers and whatnot) ?


Posted by Tulan W. Hu on September 7, 2004, 12:08 pm
Please log in for more thread options
> I am having problems getting LWP to post data to a URL that requires
> authentication. Here is the syntax I am using:
>
> my $ua = LWP::UserAgent->new(timeout => 1800);
> $ua->credentials("localhost:80", "Identification", "user",
> "password");
>
> my $response = $ua->request(
> POST 'http://localhost/some/cgi',
> Content_Type => 'application/x-www-form-urlencoded',
> Content => 'foo=bar',
> );
>
> print $response->as_string unless $response->is_success;
>
> With every request I am getting:
>
> Content-Type: text/plain
> Client-Date: Sun, 05 Sep 2004 13:08:55 GMT
> Client-Warning: Internal response
>
> 500 read timeout
>
> But if I do the reuqest myself, with the exact same URL, it works
> fine, so it is not my local CGI.
>
> What am I doing wrong? Is there any way to enable some debug flag so I
> can see more of what LWP is doing (the auth headers and whatnot) ?

I got this error message when I use Apache 1.3.31; however,
the same script runs fine on Apache 1.3.29.
Anyone else has the same experience?




Posted by BG on September 9, 2004, 12:49 pm
Please log in for more thread options
I would suggest trying Authentication other way, e.g using MIME::Base64
instead of $ua->credentials

use MIME::Base64;


$encoded = encode_base64('username:password');
my $res = $ua->post('http://localhost/some/cgi',
'Authorization' => "Basic ".$encoded,
'Content-Type' => ..... ,
Content => ....);
or
my $res = $ua->request( POST '....) will also works just fine.

BG

> > I am having problems getting LWP to post data to a URL that requires
> > authentication. Here is the syntax I am using:
> >
> > my $ua = LWP::UserAgent->new(timeout => 1800);
> > $ua->credentials("localhost:80", "Identification", "user",
> > "password");
> >
> > my $response = $ua->request(
> > POST 'http://localhost/some/cgi',
> > Content_Type => 'application/x-www-form-urlencoded',
> > Content => 'foo=bar',
> > );
> >
> > print $response->as_string unless $response->is_success;
> >
> > With every request I am getting:
> >
> > Content-Type: text/plain
> > Client-Date: Sun, 05 Sep 2004 13:08:55 GMT
> > Client-Warning: Internal response
> >
> > 500 read timeout
> >
> > But if I do the reuqest myself, with the exact same URL, it works
> > fine, so it is not my local CGI.
> >
> > What am I doing wrong? Is there any way to enable some debug flag so I
> > can see more of what LWP is doing (the auth headers and whatnot) ?
>
> I got this error message when I use Apache 1.3.31; however,
> the same script runs fine on Apache 1.3.29.
> Anyone else has the same experience?
>
>




Posted by Tulan W. Hu on September 9, 2004, 3:20 pm
Please log in for more thread options
> I would suggest trying Authentication other way, e.g using MIME::Base64
> instead of $ua->credentials
>
> use MIME::Base64;
>
>
> $encoded = encode_base64('username:password');
> my $res = $ua->post('http://localhost/some/cgi',
> 'Authorization' => "Basic ".$encoded,
> 'Content-Type' => ..... ,
> Content => ....);
> or
> my $res = $ua->request( POST '....) will also works just fine.

This is a great suggestion. It does work for both apache 1.3.29 and 1.3.31.
But I still wonder why the $ua->credentials does not work for me.
It works on 1.3.29




Posted by Jason Keirstead on October 3, 2004, 5:16 pm
Please log in for more thread options
Ok. Now I am getting a 401 Authorization Required reply.

But I am 100% positive I am submitting a valid username and password.

> > I would suggest trying Authentication other way, e.g using MIME::Base64
> > instead of $ua->credentials
> >
> > use MIME::Base64;
> >
> >
> > $encoded = encode_base64('username:password');
> > my $res = $ua->post('http://localhost/some/cgi',
> > 'Authorization' => "Basic ".$encoded,
> > 'Content-Type' => ..... ,
> > Content => ....);
> > or
> > my $res = $ua->request( POST '....) will also works just fine.
>
> This is a great suggestion. It does work for both apache 1.3.29 and 1.3.31.
> But I still wonder why the $ua->credentials does not work for me.
> It works on 1.3.29


Similar ThreadsPosted
authentication October 31, 2005, 3:32 am
lwp authentication on asp page March 23, 2005, 10:28 pm
SSL Authentication using Net::POP3 June 25, 2006, 4:40 pm
LWP and Digest authentication February 8, 2007, 1:50 pm
WWW::Mechanize and NTLM authentication December 21, 2004, 3:55 pm
Net::SSH::Perl Trouble with publickey authentication May 30, 2005, 3:58 am
Apache+MySQL+htaccess - nxt steps after authentication May 26, 2005, 2:01 pm
Perl DBI/DBD MySQL User Authentication Error June 10, 2006, 2:12 pm
Problems using GD.pm January 8, 2005, 8:05 pm
Problems when using Net::MSN 1.022 May 4, 2005, 1:20 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap