Wed Jul 25, 2007 5:00 pm
public class Fetcher {
private static final String BASE_URL = "http://www.amazon.com";
private static final String QUERY_URL = BASE_URL +
"/exec/obidos/search-handle-form/0";
// Fetches the title, ranking and review count
// for a book with a given ISBN.
public static boolean fetch(BookInfo info) throws IOException {
InputStream is = null;
OutputStream os = null;
HttpConnection conn = null;
int redirects = 0;
try {
String isbn = info.getIsbn();
String query = "index=books&field-keywords=" + isbn + "\r\n";
String requestMethod = HttpConnection.POST;
String name = QUERY_URL;
conn = (HttpConnection)Connector.open(name,
Connector.READ_WRITE);
// Send the ISBN number to perform the query
conn.setRequestMethod(requestMethod);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
os = conn.openOutputStream();
os.write(query.getBytes());
os.close();
// Read the response from the server
is = conn.openInputStream();
int code = conn.getResponseCode();
// Process the returned data (not shown here)
} finally {
// Tidy up (code not shown)
}
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.