M
Mário
Hello,
I am trying to post an object to a servlet via HTTP using the
following code,
but unfortunately, nothing is sent to the server:
private static void doJavaPost() throws IOException {
URL url = new URL("http://localhost:9999/myservlet");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
ByteArrayOutputStream data = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(data);
out.writeObject(new Date());
out.close();
OutputStream os = connection.getOutputStream();
data.writeTo(os);
os.flush();
os.close();
}
Does someone know why this does not generate a POST request?
Regards,
Mário
I am trying to post an object to a servlet via HTTP using the
following code,
but unfortunately, nothing is sent to the server:
private static void doJavaPost() throws IOException {
URL url = new URL("http://localhost:9999/myservlet");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
ByteArrayOutputStream data = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(data);
out.writeObject(new Date());
out.close();
OutputStream os = connection.getOutputStream();
data.writeTo(os);
os.flush();
os.close();
}
Does someone know why this does not generate a POST request?
Regards,
Mário