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 >
0x62590808.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature