View Single Post
Old 07-05-2006, 03:57 AM  
goldrush
Will trade SE hits for CJ hits
 
Join Date: Apr 2006
Posts: 661
Any PERL gurus in the house - LWP question?

I'm a newbie to LWP and trying to get my HTTP headers to properly emulate my browser. However, LWP keeps adding a TE header which I want to get rid of. So far I have:
Code:
#!/usr/bin/perl

use warnings;
use strict;
use LWP::UserAgent;

# this page just prints the headers sent by the client
my $url = 'http://localhost/go.php';

# initialize browser and set user agent
my $browser = LWP::UserAgent->new();
$browser->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

# create new http request, clear headers and add a new header
my $request = HTTP::Request->new(GET => $url);
$request->clear;
$request->header('Connection' => 'keep-alive');

# print the http headers before making the request
my $headers = $request->headers_as_string;
print "Headers before http request are:\n";
print "$headers";

# send the http request and print the headers echoed back by  $url
my $response = $browser->request($request);
my $contents = $response->decoded_content;
print "Returned headers are:\n";
print "$contents";
The output is:
Code:
Headers before http request are:
Connection: keep-alive
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Returned headers are:
Connection: keep-alive, TE, close
Host: localhost
TE: deflate,gzip;q=0.3
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Why is LWP adding the TE header and the extra parts to the connection header? How can I stop this behaviour?
__________________
217303611
goldrush is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote