Posting to a web page and reading the response
POST
and GET
are two types of request in HTTP to send information to or retrieve information from a website. In a GET
request, we send parameters (name-value pairs) through the web page URL itself. The POST command places the key/value pairs in the message body instead of the URL. POST
is commonly used when submitting long forms or to conceal information submitted from a casual glance.
Getting ready
For this recipe, we will use the sample guestbook
website included in the tclhttpd package. You can download tclhttpd from http://sourceforge.net/projects/tclhttpd and then run it on your local system to create a local web server. The guestbook page requests a name and URL which it adds to a guestbook to show who has visited a site when the user clicks on the Add me to your guestbook
button.
This process can be automated with a single curl
(or wget
) command.
How to do it...
Download the tclhttpd package and cd
to the bin
folder. Start the tclhttpd daemon...