Thursday, December 11, 2008

Test a HTTP request with wget

Few usefull options of the wget command to quickly test the response of a web application.

First

wget http://www.google.com
will save the result send by the server in a file with the samename as the page asked (index.html in the case of www.google.com)


use "-o" option to log the wget operation
wget -o wget.log http://www.google.com
Log you can grep 'HTTP request sent, awaiting response... 200 OK' in a script to simply know if the wget succeed

use "-O" to redirect the result in a specified file
wget -O google.index.txt http://www.google.com

"--post-file" allows you to POST data included in the specified file

wget --post-file=POSTdata.txt http://xxxxxx.yyy

Finally use "-no-check-certificate" option to don't check the server's certificate when connecting with SSL.

wget --no-check-certificate https://xxxxxx.yyy

If you need to go through proxy, just use export command before wget to specify the login, password and url of the proxy.
export http_proxy="http://login:password@proxy.exemple.org:8080"

Send a mail by tunning headers

You can do it thanks to the unix command : sendmail.

sendmail allows you to specify header fields before sending a mail thanks to "-t" option.

So you can explicitly configure mail's attributes like: From, Subject, Bcc, or even Importance, etc... (You can find
here an exhaustive list of these fields).

Here is a template called "mail.txt" containing both header and message to send :

From: XXX <xxx@mail.com>
To: YYY <yyy@mail.com>
CC: ZZZ <zzz@mail.com>
Bcc: HHH <hhh@mail.com>
Subject: Your subject
Importance: High
Content-Type: text/html
MIME-Version: 1.0
Return-Path: XXX <xxx@mail.com>
Your message.
Your message..


Then simply send the mail with command:
sendmail -t < mail.txt

Don't worry about Bcc field, it will not appear in the received mail (sendmail removes it).