tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid <...@pidster.com>
Subject Re: multipart/form-data support
Date Mon, 03 Jan 2011 14:23:47 GMT
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
> 


Mime
View raw message