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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force a proxy to reload a page every time using LWP::UserAgent

Status
Not open for further replies.

rubis

Programmer
Joined
Jun 21, 2001
Messages
54
Location
GB
The information comes partly from rfc2068 and then how that is implemented in LWP::UserAgent (using HTTP::Headers) to modify the request header.

In compliance with HTTP 1.0 the request needs to send a 'Pragma: no-cache' in the request header.

With HTTP 1.1 the preferred method is to include a 'Max-Age = 0' in the request header, though the 'no-cache [fields]' directive is also supported.

When using LWP::UserAgent this is implemented by using the headers function like so:

use HTTP::Request::Common;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->proxy('http', "$proxy:$proxy_port");
my $req = new HTTP::Request('GET', "$url");
$req->header('pragma' => 'no-cache', #HTTP 1.0 header
'max-age' => '0'); #HTTP 1.1 header

my $request = $req->as_string(); #contains the full request
my $html = $ua->request($req)->as_string; #contains the returned html

This assumes $proxy, $proxy_port and $url are all defined earlier.

(written by Wyzelli -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top