I need to emulate a HTTP post with direct Java code. I'm doing doing something like this:
URL url = new URL("HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
Writer writer = new OutputStreamWriter(conn.getOutputStream());
writer.write("test");
writer.flush();
I never hit the doPost method in the target servlet even though I get no errors. I'm guessing I need to encode what I'm writing to properly post but am unsure how. I've done some research on the REST architecture which is along the lines of what I'm trying to do but can't find simple examples that don't require 3rd party software.
URL url = new URL("HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
Writer writer = new OutputStreamWriter(conn.getOutputStream());
writer.write("test");
writer.flush();
I never hit the doPost method in the target servlet even though I get no errors. I'm guessing I need to encode what I'm writing to properly post but am unsure how. I've done some research on the REST architecture which is along the lines of what I'm trying to do but can't find simple examples that don't require 3rd party software.