I am writing an applet that can crop an image and upload it to the server.
I would like to post the image data to a .php file on the server using a form POST method.
How to do this?
I worked with HttpUrlConnections and DataOutputstreams, but I don't exactly know how to use it.
The following is the code I distilled from several posts. Yet, it is not finished:
Please help. I thank you in advance.
I would like to post the image data to a .php file on the server using a form POST method.
How to do this?
I worked with HttpUrlConnections and DataOutputstreams, but I don't exactly know how to use it.
The following is the code I distilled from several posts. Yet, it is not finished:
Code:
String u = "[URL unfurl="true"]http://bla/bla.php";[/URL]
try {
URL url = new URL(u);
try {
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
huc.setRequestMethod("POST");
huc.setDoOutput(true);
huc.setUseCaches(false);
huc.setRequestProperty ("Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
huc.setRequestProperty ("Content-Length",new Integer(message.length()).toString());
DataOutputStream dos = new DataOutputStream(huc.getOutputStream());
dos.writeBytes(WHAT TO PUT HERE???);
dos.flush();
dos.close();
huc.disconnect();
}
catch(IOException ioexception) {
ioexception.printStackTrace();
}
}
catch(MalformedURLException malformedurlexception) {
malformedurlexception.printStackTrace();
}
Please help. I thank you in advance.