|
try { // Create new URL and connect URL url = new URL(protocol + "://" + hostname + prefix + service);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Setup HTTP POST parameters
connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false);
// Get POST data from input file (XML Document)
String queryString = readInputFile(infile);
// POST data OutputStream out = connection.getOutputStream();
try { out.write(queryString.getBytes()); out.close();
// Get Response HTTP Header parameters if (connection.getResponseCode() == 302) {
String data = ""; try {
data = readURLConnection(connection);
} catch (Exception e) {
// exception raised because HTTP status of 400/500 occur, do nothing
} try {
writeOutputFile(data, outfile);
} catch (Exception e) {
System.out.println("Error writing output file " + outfile);
} } catch (Exception e) { System.out.println("Error sending data to server");
} } catch (Exception e) { System.out.println(e); }
|