Script 4

Presentation Notes

Well, let's first try POSTing directly in the browser. We'll got to petfinder.com and see what happens when we do a search.

If my current dog was not dog-aggressive (but is very people-friendly), my wife and I would probably have more dogs by now. My wife would love to have an Alaskan Malamute. Let's see what dogs that are adult male Malamutes are available in the NJ area.

OK, we got results. Notice the results page URL, though? No search terms. Forms that use POST do not put the search terms in the URL, as mentioned earlier. We're going to have to look at the search page's HTML source code to find out what the fields are called. The baseURL seems to be http://www.petfinder.com/pet.cgi

HTTP is just a simple way for a computer to say "Hey, give me some information back", as I'm sure you know. One method is to just send a URL to a server, and it then sends a bunch of ASCII (or binary) back to your computer, which is waiting for the response. We've already seen how to find this method - it's called GET.

However, sometimes there is just too much information to fit in an URL (or the website doesn't want data sent in URLs). So, there is the POST method, which means that your request includes the fields as a separate part of your request to the web server.

The site we're trying to access uses POST. Let's take a look at the source code of the page. The form tags we want (there can be more than one) are there - we'll look after where we find PET SEARCH. See what the ACTION parameter equals (this happens to be a relative URL, which means you need to look at the URL of the page we are on). Also, notice that the method is POST. Since it is POST in our example, we'll need to attach the data separately from the URL. The command-line utility curl can do this using the --data option.

Look for the tags to get the fields' names. We will also need