public InputStream sendMessage ( Properties args , int method ) throws IOException { // Set this up any way you want -- POST can be used for all calls, // but request headers cannot be set in JDK 1.0.2 so the query // string still must be used to pass arguments. if ( method == GET ) { URL url = new URL ( servlet . toExternalForm ( ) + "?" + toEncodedString ( args ) ) ; return url . openStream ( ) ; } else { URLConnection conn = servlet . openConnection ( ) ; conn . setDoOutput ( true ) ; conn . setUseCaches ( false ) ; // POST the request data (html form encoded) PrintStream out = new PrintStream ( conn . getOutputStream ( ) ) ; if ( args != null && args . size ( ) > 0 ) { out . print ( toEncodedString ( args ) ) ; } out . close ( ) ; // ESSENTIAL for this to work! // Read the POST response data return conn . getInputStream ( ) ; } }
Send the request . Return the input stream with the response if the request succeeds .