tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pankaj Tiwari <panky.tiw...@gmail.com>
Subject multipart/form-data support
Date Mon, 03 Jan 2011 03:06:55 GMT
I have been trying to send multipart/form-data to the server. I have found
that the request never reaches the server.
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");
            con.setRequestProperty("Connection", "Keep-Alive");

            OutputStream out = con.getOutputStream();
            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();
            oos.close();
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

Thanks,
Pankaj

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message