Java Reference
In-Depth Information
This list will be displayed in the drop down list.
Once you actually select a state, the following request is sent:
http://www.httprecipes.com/1/10/statehtml.php?state=MO
The above URL requests state information for Missouri, which has the postal code of
“MO”. The following HTML would be returned:
<h1>Missouri</h1>
<img src="/images/states/MO.png" border="1"><br>
<table border="0">
<tr><td><b>Capital:<b></td><td>Jefferson City</td></tr>
<tr><td><b>Code:<b></td><td>MO</td></tr>
<tr><td><b>Official Site:<b></td><td><a href="http://www.state.
mo.us/">http://www.state.mo.us/</a></td></tr>
</table>
Of course, this is not a complete HTML page. There is no <html> or <body> tags.
This HTML will be displayed under the input area, once the user selects the desired state.
Writing a Bot for the Non-XML AJAX Site
We will now construct a bot that can download the state information. When you want to
write a bot for an AJAX site, your job is to send the same requests as the web browser. The
bot we are creating will send the same request as the web server when the state information
was requested. You can see this recipe in Listing 10.1.
Listing 10.1: Non-XML AJAX Bot (AjaxNonXML.java)
package com.heatonresearch.httprecipes.ch10.recipe1;
import java.io.*;
import java.net.*;
public class AjaxNonXML
{
// the size of a buffer
public static int BUFFER_SIZE = 8192;
/**
* This method downloads the specified URL into a Java
* String. This is a very simple method, that you can
* reused anytime you need to quickly grab all data from
* a specific URL.
*
Search WWH ::




Custom Search