# And then we update the URL based on the Location:-header. my $referral_uri = $response->header('Location'); #### package FixRedirectLWPUserAgent; ########################################################## # Derived from LWP::UserAgent # Handle redirect_ok method to fix double Location header. ########################################################## use strict; use warnings; use LWP::UserAgent; our @ISA = qw( LWP::UserAgent ); sub redirect_ok { my ($self, $prospective_request, $response) = @_; # Check response for multiple location headers. my @locations = $response->header('Location'); if (scalar(@locations) > 1) { my $uri = $prospective_request->uri(); my @uris = split /, /,$uri; $prospective_request->uri($uris[0]) if scalar @uris; } # Call parent to do all the boring work. my $ok = $self->SUPER::redirect_ok($prospective_request, $response); return $ok; } 1;