I want to upload a file (GPX file, which is similar to XML) to a URL (http://www.gpsvisualizer.com/map_input). Then wait for the map to be generated and retrieve it. The developer has stated this is possible, but I am not getting anywhere. Here is my code so far:
private static void postData(File fileName) {
File input = fileName;
//Setup connection
URL url = new URL("http://www.gpsvisualizer.com/map");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 1.2.30703)");
//Send file
OutputStream os = connection.getOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
FileReader fileReader = new FileReader(input);
StreamSource source = new StreamSource(fileReader);
StreamResult result = new StreamResult(os);
transformer.transform(source, result);
os.flush();
//Retrieve response
BufferedReader br = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String line = br.readLine();
while ( line != null ) {
System.out.println(line);
line = br.readLine();
}
br.close();
}
All this is doing, is setting up the connection, when I get the response, I am only getting the HTML of the initial page, not the (should be) map one.