Public said:
Please give me a line or two showing how to use proxy..
In UserAgent it is:
$ua->proxy(['http', 'ftp'], '
http://proxy.sn.no:8001/');
Can do use the same line in Net:Http? I don' know how use use 2616.
No. As Gisle Aas wrote, you have to do a low level connection yourself.
Thank goodness, the difference between a direct connection and a
connection via proxy is minimal. The gist is:
For a normal connection, you
- connect to a host/port, and
- request for a URL that looks like an absolute Unix path. (= relative
to the domain root)
For a proxy connection, you
- connect to the proxy, and
- request for an absolute URL, including protocol ("http"), domain and
optionally, port.
Here's an example modified from the Synopsis of Net::Http, which
requests a page on a port different from the default for http, 80:
use Net::HTTP;
my $s = Net::HTTP->new(Host => "modperl.com", PeerPort => 9000)
or die $@;
$s->write_request(GET => "/perl_networking/errata.html");
my($code, $mess, %h) = $s->read_response_headers;
print "Response code: $code ($mess)\n";
use Data:

umper;
print Data:

umper->Dump([\%h], ['*headers']);
print "\n";
{
my $n = $s->read_entity_body(my $buf, 1024);
die "read failed: $!" unless defined $n;
print $buf;
redo if $n;
}
Here is it again, for another URL, and modified to connect via the proxy
of my ISP (<
http://proxy.pandora.be:8080>):
use Net::HTTP;
my $s = Net::HTTP->new(Host => "httpd.apache.org",
PeerAddr => 'proxy.pandora.be', PeerPort => 8080) or die $@;
$s->write_request(GET =>
"
http://httpd.apache.org/docs/misc/FAQ.html");
my($code, $mess, %h) = $s->read_response_headers;
print "Response code: $code ($mess)\n";
use Data:

umper;
print Data:

umper->Dump([\%h], ['*headers']);
print "\n";
{
my $n = $s->read_entity_body(my $buf, 1024);
die "read failed: $!" unless defined $n;
print $buf;
redo if $n;
}
IMO the code to retrieve data via a proxy is actually simpler than for a
normal connection, because (almost) everything but the URL for the GET
is constant.
n.b. I think the Host property is mainly important if you encounter name
based virtual hosts, otherwise you could get pages from the wrong
domain.