Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How can I capture the full header of a cgi script?

by slloyd (Hermit)
on Nov 29, 2007 at 13:19 UTC ( [id://653826]=perlquestion: print w/replies, xml ) Need Help??

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

Is there a simle lightweight way to analyze the header of a cgi request? I understand how if I were a server listening on a socket but I cannot think of a way to see the full header from a cgi script. Is there a way?

-------------------------------
Need a good Perl friendly Host Provider?
http://www.dreamhost.com

  • Comment on How can I capture the full header of a cgi script?

Replies are listed 'Best First'.
Re: How can I capture the full header of a cgi script?
by moritz (Cardinal) on Nov 29, 2007 at 13:31 UTC
    My favorite methods is wget -S $url on the command line.
Re: How can I capture the full header of a cgi script?
by Cubes (Pilgrim) on Nov 29, 2007 at 13:27 UTC
    There are a lot of ways to do this, but a couple of simple ones are:

    - Use the Web Developer add-on / toolbar in Firefox. Under "Information" is a menu option that will display the http response headers.

    - Put a print "Content-Type: text/plain\n\n" at the top of your script, before you send any headers. This will display the headers in your web browser (which now thinks they're part of the page content). Of course, you'll need to remove the print statement once you're done debugging.

Re: How can I capture the full header of a cgi script?
by Corion (Patriarch) on Nov 29, 2007 at 14:11 UTC

    If you have LWP installed, it comes with the GET utility, which is incredibly useful for just that:

    GET -USe http://google.com
Re: How can I capture the full header of a cgi script?
by sh1tn (Priest) on Nov 29, 2007 at 13:58 UTC
    You may want to try WWW::Mechanize

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get("http://perlmonks.net"); my $headers = $mech->response->headers->as_string;


Re: How can I capture the full header of a cgi script?
by zentara (Archbishop) on Nov 29, 2007 at 14:51 UTC
    #!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use Data::Dumper; my $url = 'http://youtube.com/watch?v=2cBVpTRoMjI'; my $ua = LWP::UserAgent->new(); my $result = $ua->head($url); my $remote_headers = $result->headers; print Dumper(\$remote_headers);

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://653826]
Approved by almut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-16 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found