HTTP Control

The HTTP Control provides a simple API for performing HTTP GET and POST operations.  A GET operation is performed as follows:

StringBuffer responseHolder = new StringBuffer();
Map map = new HashMap();
MapDataAdapter data = new MapDataAdapter(map);
map.put("s", "BEAS");
URL target = new URL("http://finance.yahoo.com/q");

int responseCode = httpControl.get(target, data, responseHolder);

System.out.println("The HTTP Status code is " + responseCode);
System.out.println("The response text is " + responseHolder.toString());

The get() method requires a URL to invoke on.  It requires an instance of the DataAdapter interface to define what parameters are involved in the GET.  And it requires a StringBuffer instance to store the response in.  Finally, the HTTP Status code is returned by the get() call.

The control comes with one implementation of the DataAdapter interface, namey MapDataAdapter, which uses a java.util.Map instance to store its parameters.  Other implementations are possible.

HTTP POST operations are performed in a similar way, except the post() method is designed to be "fire and forget" in that there is no HTTP response code returned, neither is there response text returned.  It is invoked as follows:

Map map = new HashMap();
MapDataAdapter data = new MapDataAdapter(map);
map.put("s", "BEAS");
URL target = new URL("http://finance.yahoo.com/q");

httpControl.post(target, data);