Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I write a script that sends a get request to a web page and returns nicely formatted http headers?

share|improve this question
Platform, scripting language, any other detail you'd like to give? – sparks May 21 '09 at 22:09
up vote 1 down vote accepted

try this nasty hack:

wget -O - -o /dev/null --save-headers | \
awk 'BEGIN{skip=0}{ if (($0)=="\r") {skip=1;}; if (skip==0) print $0 }'
share|improve this answer

One option might be to use curl with the --dump-header option.

share|improve this answer

There are quite a few modules in many different languages that will retrieve HTTP headers for you.

etc, etc.

share|improve this answer

curl has support to view the headers when you're downloading, or you can use the -I option to save the headers to a file.

share|improve this answer

If you just want to view the headers.. (Not programatically) just use [live http headers][1] plugin for mozilla firefox.

share|improve this answer
Now that firefox is mentioned, I just have to recommend FireBug. Perfect for analyzing what happens on a page - including network traffic. – Commander Keen May 22 '09 at 10:40
This is indeed what I use now - Firebug has excellent header tools. But they are a pain in the ass to copy and paste from, Firbug is not super-stable, and you can't script it to automatically check headers on multiple files. – deadprogrammer May 22 '09 at 15:43

This bash function will take an URL + method, or Server + path + method + port. If you use "HEAD" method, it will return the headers, if you use GET, it will return all headers and the whole reply. Supports https through openssl.

function httpreq ()
    if [ $# -eq 0 ]; then echo -e "httpreq SERVER PATH [GET/HEAD] [PORT]\nOR\nhttpreq URL [GET/HEAD]"; return 1; fi
    if echo $1 | grep -q "://"
        SUNUCU=$(echo $1 |cut -d '/' -f3 | cut -d':' -f1)
        YOL=/$(echo $1 |cut -d '/' -f4-)
        PROTO=$(echo $1 |cut -d '/' -f1)
        PORT=$(echo $1| sed -n 's&^.*://.*:\([[:digit:]]*\)/.*&\1&p')
        if [ -z $PORT ]
            if [ $PROTO == "https:" ]; then PORT=443; else PORT=80; fi
    if [ $PROTO == "https:" ];
     echo -e "$METHOD $YOL HTTP/1.1\r\nHOST:$SUNUCU\r\n\r\n" | openssl s_client -quiet -connect $SUNUCU:$PORT
     echo -e "$METHOD $YOL HTTP/1.1\r\nHOST:$SUNUCU\r\n\r\n" | nc $SUNUCU $PORT
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.