1. Keep-Alive - I am not sure if that should cause any issues here. 2. The request never reaches the server. I have tried without the last connect as well but nothing seems to work here.
When I run this piece of code, I do not get any exceptions or error on the client side but the request does not seems to be reaching the server. (doGet/doPost methods are never called). Q1. How can i debug if the request is being sent from the java client at all? If it had been a browser, I could have used a header monitoring plugin but not sure about java application Q2. Is there any chance that tomcat does not support or ignores such request (multipart file-data)? On Mon, Jan 3, 2011 at 7:53 PM, Pid <p...@pidster.com> wrote: > On 1/3/11 3:06 AM, Pankaj Tiwari wrote: > > I have been trying to send multipart/form-data to the server. I have > found > > that the request never reaches the server. > > Doesn't sound like a Tomcat problem to me then... > > > This is my client code, if I am missing something core in here. > > > > public static void main(String args[]) > > { > > try > > { > > URL url = new URL(SERVERURL); > > HttpURLConnection con = (HttpURLConnection) > > url.openConnection(); > > > > con.setDoInput(true); > > con.setDoOutput(true); > > con.setUseCaches(false); > > > > con.setRequestProperty("Content-Type", > > "multipart/form-data;boundary=" + BOUNDARY); > > con.setRequestMethod("POST"); > > Why are you using keep alive? > > > con.setRequestProperty("Connection", "Keep-Alive"); > > > > OutputStream out = con.getOutputStream(); > > Why are you using a DataOutputStream? > > > DataOutputStream oos = new DataOutputStream(out); > > oos.writeBytes(TWOHYPHENS + BOUNDARY + LINEEND); > > oos.writeBytes("Content-Disposition: form-data; > name=\"name\"" + > > LINEEND); > > oos.writeBytes(LINEEND); > > oos.write("HI".getBytes("UTF-8")); > > oos.writeBytes(LINEEND); > > oos.writeBytes(TWOHYPHENS + BOUNDARY + TWOHYPHENS + LINEEND); > > oos.flush(); > > con.connect(); > > Why are you connecting after you've attempted to write data? > > > p > > > oos.close(); > > } > > catch (MalformedURLException e) > > { > > e.printStackTrace(); > > } > > catch (IOException e) > > { > > e.printStackTrace(); > > } > > } > > > > Thanks, > > Pankaj > > > > -- Pankaj Tiwari