URL url = new URL("http://jrserver:8888");
URLConnection uc = url.getConnection();
if (uc instanceof HttpURLConnection) {
HttpURLConnection huc = (HttpURLConnection)uc;
//set use POST method.
huc.setRequestMethod("POST");
huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
huc.setDoOutput(true);
//write the HTTP query to the output stream.
OutputStreamWriter writer = new OutputStreamWriter(huc.getOutputStream());
writer.write("jrs.cmd=jrs.get_subnodes");
writer.close();
huc.getHeaderField(0);
//get the response content from the server.
InputStream inStream = uc.getInputStream();
if (inStream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
String inputLine;
while (null != (inputLine = reader.readLine())) {
System.out.println(inputLine);
}
}
}
|