Real Time Information Director User Documentation

RTID Message Format and Programmatic Interfaces
Hewlett-Packard Company 12 529618 - 002
5. Use the setRequestMethod method of the HttpURLConnection object to specify a
POST operation:
urlConn.setRequestMethod("POST");
Use the getOutputStream method of the HttpURLConnection object to identify
the destination, and the input and output objects to write the stream. This step
might involve converting an input file to a stream first:
InputStream inputStream = new FileInputStream(fileName)
then passing the stream to an object that writes it to the servlet:
postrequest(inputStream)
protected void postRequest(InputStream inputStream)
throws IOException
{
// how about
BufferedReader input = new BufferedReader(new
InputStreamReader(inputStream));
BufferedWriter output = new BufferedWriter(new
OutputStreamWriter(urlConn.getOutputStream ()));
String inputLine;
while((inputLine = input.readLine())!= null)
{
output.write(inputLine);
}
// cleanup output stream
output.flush();
output.close();
}
6. Use the getInputStream method of the HttpURLConnection object to get the
response from the servlet. Catch any exception.
try{
responseReader = new BufferedReader(new
InputStreamReader(urlConn.getInputStream ()));
// process the response data
String inputLine;
while((inputLine = responseReader.readLine())!= null)
{
System.out.println(inputLine);
}
}catch(IOException ioe){
7. In the IOException catch block, use the getErrorStream method of the
HttpURLConnection object to get any exception message, and process the
exception message as appropriate to the application :