criz has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm hoping someone can offer insite to this issue. I'm using libwww library to retrieve a tab delimited text file through HTTP. I needed to do this since there is basic authentication, plus I need to check header information such as status and document title. The request is printed to an output file. However, I do not want the header to be printed. Is there any way to supress this? Here's a sample of what I'm doing:
$req = HTTP::Request->new(GET => $myrequeststring); $req->authorization_basic('username','password'); $res = $ua->request($req); #Check the request if ($res->is_success) { print OUT $ua->request($req)->as_string; } else { print STDOUT "Error: " . $res->status_line . "\n"; }
The output file always has these headers, which I want to remove:
HTTP/1.1 200 OK Cache-Control: private Connection: close Date: Mon, 06 Jun 2005 16:41:28 GMT Server: Microsoft-IIS/5.0 Content-Length: 420 Content-Type: text/html Expires: Mon, 06 Jun 2005 16:40:29 GMT Client-Date: Mon, 06 Jun 2005 16:41:22 GMT Client-Peer: 204.255.44.151:80 Client-Response-Num: 1 Set-Cookie: ASPSESSIONIDQQQQGUUO=JIPPOIADCAKNEGMGFAHOGJAE; path=/ Title: Empty result
Thanks in advance for any help.

Replies are listed 'Best First'.
Re: Removing http headers from LWP::Useragent request
by davidrw (Prior) on Jun 06, 2005 at 16:46 UTC
    Simply use the ->content method instead of ->as_string (See HTTP::Request manpage)
      Thanks! On a related note, is it possible to parse the request prior to printing it to output? There are certain fields that I would like to suppress from from the file.
        sure -- you can store the content in a variable first before printing... also, the headers are available via the ->header() method (See HTTP::Headers docs).
        my $content = $ua->request($req)->content; # munge $content here # $content = uc $content; print OUT $content; my $title = $ua->request($req)->header('Title'); warn $title; # 'Empty Result'