I`m using the following code to submit a form:
URL url = new URL(submit_url);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=*****");
connection.setRequestProperty("Cookie", cookie);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
bw.write(query);
bw.write("\r\n");
bw.flush();
bw.close();
But I need to submit a file, too. The file input name is: file and my file is located at: d:/images/test.gif Please help me to submit the image, too. The query is a string: name=username&title=title