#! /usr/bin/perl -w ######################################### # no302.pl v1.0 # Released 12/03/2008 # By mckt [http://skeptikal.org] # # This code is released under the GPLv3. If you need to replicate its functionality in a non-GPL # package, write your own two dozen lines of code. # ######################################### # usage: perl no302.pl http://site.com/page.php # # to post data (login credentials, etc) use the "$fieldname $value $fieldname $value" format: # perl no302.pl http://site.com/page.php username admin password secret use strict; use LWP::UserAgent; my $url = shift || die('Supply a url to hit'); my %postData; my $isPost = 0; while($_ = shift){ $isPost = 1; $postData{$_} = shift; } my $ua = new LWP::UserAgent; $ua->max_redirect(0); # Don't follow 302 redirects my $r = undef; if(!$isPost){ $r = $ua->get($url); }else{ $r = $ua->post($url, \%postData); } print $r->status_line."\n\n"; print $r->content."\n\n";