You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Pid <pi...@pidster.com> on 2011/01/03 18:08:54 UTC

[OT] Re: multipart/form-data support

On 1/3/11 2:55 PM, Pankaj Tiwari wrote:
> 1. Keep-Alive - I am not sure if that should cause any issues here.

Why set it if you're not reusing the connection?

> 2. The request never reaches the server. I have tried without the last
> connect as well but nothing seems to work here.

Check the response status code: con.getResponseCode()

> 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

GIYF: Wireshark.

> Q2. Is there any chance that tomcat does not support or ignores such request
> (multipart file-data)?

Tomcat doesn't care what the body of the request looks like.


p

> On Mon, Jan 3, 2011 at 7:53 PM, Pid <pi...@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
>>>
>>
>>
> 
>