LWP gives 302 Found after update?
flag
6 messages - Collapse all
/groups/adfetch?adid=cOpyERAAAABTt3ihe5YfQ0BzzkjGloX5
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
1.  John Bokma  
View profile  
 More options Aug 16 2005, 2:05 pm
Newsgroups: comp.lang.perl.misc
From: John Bokma <j...@castleamber.com>
Date: 16 Aug 2005 18:05:50 GMT
Local: Tues, Aug 16 2005 2:05 pm
Subject: LWP gives 302 Found after update?
The following script used to work (Logs in to a PHPbb message board):

use strict;
use warnings;

use LWP::UserAgent;
use LWP::Debug qw(+);

my $ua = LWP::UserAgent->new();

my $response = $ua->post(

    "http://toxicice.com/login.php", [

        username => 'xxxxxxx',
        password => 'xxxx',
        autlogin => 'off',
        redirect => '',
        login    => 'Log in',
    ]
);
$response->is_success or
    die "Login failed: ", $response->status_line, "\n";

With an invalid username/password (as above), it gives:

LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST http://toxici
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 398 bytes

... snipped ...

LWP::Protocol::collect: read 188 bytes
LWP::UserAgent::request: Simple response: OK

However, with a valid one it gives:

LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST http://toxicice.com/login.php
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::UserAgent::request: Simple response: Found
Login failed: 302 Found

$response->content is empty ('').

I updated some time ago to a more recent version of ActiveState Perl,
and probably LWP was upgraded as well. OTOH it might be a server thing.

perl -v
...
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
...

query *
...
libwww-perl          [5.803.0.1] Web API for Perl
...

(Complete script is at:
http://johnbokma.com/perl/phpbb-remote-backup.html )

( If you want to test but have no PHP board, mail: phpbb at johnbokma
dot com, and I arrange a test log in, don't create a test login
yourself, thanks )

--
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
2.  Brian Wakem  
View profile  
 More options Aug 16 2005, 2:43 pm
Newsgroups: comp.lang.perl.misc
From: Brian Wakem <n...@email.com>
Date: Tue, 16 Aug 2005 19:43:37 +0100
Local: Tues, Aug 16 2005 2:43 pm
Subject: Re: LWP gives 302 Found after update?

John Bokma wrote:
> Login failed: 302 Found

> $response->content is empty ('').

The page is printing a Location: header, which tells the browser to go
somewhere else.  LWP::UserAgent does not follow this by default for POSTs.

Add this:-

push @{ $ua->requests_redirectable }, 'POST';

--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
3.  John Bokma  
View profile  
 More options Aug 16 2005, 2:50 pm
Newsgroups: comp.lang.perl.misc
From: John Bokma <j...@castleamber.com>
Date: 16 Aug 2005 18:50:52 GMT
Local: Tues, Aug 16 2005 2:50 pm
Subject: Re: LWP gives 302 Found after update?

Brian Wakem <n...@email.com> wrote:
> John Bokma wrote:

>> Login failed: 302 Found

>> $response->content is empty ('').

> The page is printing a Location: header, which tells the browser to go
> somewhere else.  LWP::UserAgent does not follow this by default for
> POSTs.

> Add this:-

> push @{ $ua->requests_redirectable }, 'POST';

Aargh, it was even in the manual :-( Many thanks, it fixed my script. I
have no idea however, why it started to fail in the first place. Was POST
removed from the list recently? (I can't remember I updated PHPbb
recently).

--
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
4.  Brian Wakem  
View profile  
 More options Aug 16 2005, 2:56 pm
Newsgroups: comp.lang.perl.misc
From: Brian Wakem <n...@email.com>
Date: Tue, 16 Aug 2005 19:56:55 +0100
Local: Tues, Aug 16 2005 2:56 pm
Subject: Re: LWP gives 302 Found after update?

John Bokma wrote:
> Aargh, it was even in the manual :-( Many thanks, it fixed my script. I
> have no idea however, why it started to fail in the first place. Was POST
> removed from the list recently? (I can't remember I updated PHPbb
> recently).

I don't recall POST ever being in that redirectable array.  I've only been
using Perl for 5yrs though.

--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
5.  J. Gleixner  
View profile  
 More options Aug 16 2005, 3:35 pm
Newsgroups: comp.lang.perl.misc
From: "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
Date: Tue, 16 Aug 2005 14:35:20 -0500
Local: Tues, Aug 16 2005 3:35 pm
Subject: Re: LWP gives 302 Found after update?

Brian Wakem wrote:
> John Bokma wrote:

>>Aargh, it was even in the manual :-( Many thanks, it fixed my script. I
>>have no idea however, why it started to fail in the first place. Was POST
>>removed from the list recently? (I can't remember I updated PHPbb
>>recently).

More likely is that the Web site changed something.

> I don't recall POST ever being in that redirectable array.  I've only been
> using Perl for 5yrs though.

Much older versions used redirect_ok(), which was:

sub redirect_ok
{
     # draft-ietf-http-v10-spec-02.ps from www.ics.uci.edu, specify:
     #
     # If the 30[12] status code is received in response to a request using
     # the POST method, the user agent must not automatically redirect the
     # request unless it can be confirmed by the user, since this might
change
     # the conditions under which the request was issued.

     my($self, $request) = @_;
     return 0 if $request->method eq "POST";
     1;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
6.  J. Gleixner  
View profile  
 More options Aug 16 2005, 2:48 pm
Newsgroups: comp.lang.perl.misc
From: "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
Date: Tue, 16 Aug 2005 13:48:33 -0500
Local: Tues, Aug 16 2005 2:48 pm
Subject: Re: LWP gives 302 Found after update?

Just a quick guess...  Dumping $ua:

$VAR1 = bless( {
                  'max_redirect' => 7,
                  'protocols_forbidden' => undef,
                  'no_proxy' => [],
                  'protocols_allowed' => undef,
                  'use_eval' => 1,
                  'requests_redirectable' => [
                                               'GET',
                                               'HEAD'
                                             ],
                  'from' => undef,
                  'timeout' => 180,
                  'agent' => 'libwww-perl/5.803',
                  'def_headers' => undef,
                  'parse_head' => 1,
                  'proxy' => {},
                  'max_size' => undef
                }, 'LWP::UserAgent' );

Since a 302 means a redirect is being requested, and
'requests_redirectable' only contain GET and HEAD requests, possibly the
POST isn't seen as being redirecable. Maybe adding 'POST' to that
attribute, or possibly doing a GET will resolve it.

WWW::Mechanize might provide a better interface, for interacting with
the site.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2013 Google