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

HTTP headers, not as string

Status
Not open for further replies.

motte

Programmer
May 31, 2001
155
US
I haven't had the need for this in a while, but I know there is a function that gets the HTTP headers w/o having to manually parse them.

I thought it was with HTTP::Headers.
Something as easy as calling a function such as headers() would return an array of headers. But I can't remember how this would work and what would do it.

Anyone know?

Mike
 
You talking about this:

Code:
use CGI qw(:standard);
print header;
print start_html("Hello World");
print "<h2>Hello, world!</h2>\n";
print end_html;
 
I think what you want is this:

Code:
use HTTP::Lite ;
$HTTPHandle = new HTTP::Lite ;

$request = $HTTPHandle->request("[URL unfurl="true"]http://www.google.com")[/URL]
    or die("This was bad and painful!") ;

@iLoveArrays = $HTTPHandle->headers_array();

If it is this... please let me know coz I have some trouble with the use of HTTP::Lite.
 
naq2,

You are working down the right path, but I'm not sure if that is it. We don't have HTTP::Lite installed, and since it has been a while since I used whatever I am talking about, I'm not sure if it was Lite that was used before we upgraded. But I believe it was something else. I think it was from an inheritable base class that should never be instantiated, but I can't remember which.

mike
 
Mike,

I would have though the Rob's suggestion would be the one you want, but then I see "manually parse", and this makes me wonder ...

HTML::TokeParser::[Simple] if you're talking about parsing html

Have a look on look for HTML::parse

--Paul



It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
You know, I was really dumb on this. This is it here:

Code:
#!/usr/bin/perl

use strict;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

my $request = HTTP::Request->new('POST', '[URL unfurl="true"]http://myurl/http/postto.cgi');[/URL]

my $response = $ua->request($request);
my %headers = %{$response->headers};
foreach my $h (keys %headers){
  print qq($h: $headers{$h}\n);
}

print $response->content();
 
HTTP::Request
if not a simple
use HTTP::Request might sort it out

Is this solved?

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top