Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

403 Forbidden/LWP UserAgent - please help

Status
Not open for further replies.

IVJP

Programmer
Jul 21, 2014
11
US
Hello Tek-Tippers,

I am having a problem accessing an asp.net site and get a 403 Forbidden error with my script. This does not happen to any html type website so I am asking you for help to scrape asp.net site.

Thank you in advance for all the help.


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


my $ua = new LWP::UserAgent;
my $url = ' my $cookie_jar = HTTP::Cookies->new;


$ua->proxy("http", "proxysite:80");

my $req = new HTTP::Request GET => $url;
my $res = $ua->request($req);
$req = $res->request();
$cookie_jar->extract_cookies($res);

print "\nREQUEST-HEADERS\n";
print $req->headers_as_string();
print "\nREQUEST-CONTENT\n";
print $req->content;
if ($res->is_success) {
print "\nRESPONSE-HEADERS\n";
print $res->headers_as_string();
print "\nRESPONSE-CONTENT\n";
print $res->content;
} else {
print "\nRESPONSE-ERROR\n";
print $res->error_as_HTML();
}


Output:
REQUEST-HEADERS
User-Agent: lib
REQUEST-CONTENT

RESPONSE-ERROR
<html>
<head><title>An Error Occurred</title></head>
<body>
<h1>An Error Occurred</h1>
<p>403 Forbidden</p>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top