Leser: 16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Create a user agent object
use LWP::UserAgent;
use strict;
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
$ua->proxy(['http'], '151.100.59.11:3128');
# Create a request
my $req = HTTP::Request->new(GET => 'http://www.google.com/');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
#Pass request to the user agent and get a response back
my $res = $ua->request($req);
my $httpResponse;
#Check the outcome of the response
if ($res->is_success) {
$httpResponse = $res->content;
}
else {
print $res->status_line, "\n";
}
Quote$ua->proxy(['http', 'ftp'], 'http://proxy.example.org:8001/');