commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Garrett Smith" <dhtmlkitc...@gmail.com>
Subject Re: "Stream ended unexpectedly" - simple testcase
Date Sat, 19 Jul 2008 19:12:53 GMT
On Sat, Jul 19, 2008 at 6:48 AM, Aaron Freeman <aaron@sendthisfile.com> wrote:
> I think you also need two newlines after the Content-Disposition.  Try:
>

That did it.

http://tools.ietf.org/html/rfc2046

 ..the initial CRLF is considered to be attached
   to the boundary...

...The body must then contain
   one or more body parts, each preceded by a
   boundary delimiter line, and the last one followed
   by a closing boundary delimiter line. After its
   boundary delimiter line, each body part then
   consists of a header area, a blank line, and a body area...

So there should be a CRLF after content-disposition and one before the
boundary. That makes two CRLF.

And now I can serialize and send a form over XHR.

Garrett

> -a
>
>> -----Original Message-----
>> From: Garrett Smith [mailto:dhtmlkitchen@gmail.com]
>> Sent: Thursday, July 17, 2008 11:24 AM
>> To: Commons Users List
>> Subject: Re: "Stream ended unexpectedly" - simple testcase
>>
>> On Thu, Jul 17, 2008 at 7:00 AM, Aaron Freeman
>> <aaron@sendthisfile.com> wrote:
>> > Shouldn't there be a newline after the content ("a")? In otherwords
>> > shouldn't --DATA1215979532633-- be on its own line?
>> >
>>
>> I think you're right.
>>
>> req.send('--DATA1215979532633\r\n'
>>     +'Content-Disposition: form-data; name="name";'
>>     +'\r\na\r\n'
>>     +'--DATA1215979532633--');
>>
>>
>> But I still get the error: "Stream ended unexpectedly."
>>
>> Full source code:
>> ============================================
>> <!DOCTYPE HTML>
>> <html lang="en">
>> <head>
>>   <title>Form Serialize</title>
>> </head>
>> <body>
>> <form method="post"
>>   enctype="multipart/form-data"
>>   id='form' action="process.jsp">
>>   <input type="text" name="name" value="a"/>
>>   <button type="button"
>>     onclick="sendXHR(event);return false;">Send</button> </form>
>>
>> <pre id="result"></pre>
>>
>> <script>
>> function sendXHR(e) {try{
>>   var req = new XMLHttpRequest();
>>   req.oreadystatechange = showData;
>>   req.open("post", "process.jsp", true);
>>   req.setRequestHeader('Content-Type',
>>     "multipart/form-data; boundary=DATA1215979532633");
>>   req.send('--DATA1215979532633\r\n'
>>     +'Content-Disposition: form-data; name="name";'
>>     +'\r\na\r\n'
>>     +'--DATA1215979532633--');
>>     }catch(ex){alert(ex);}
>> }
>>
>>
>> function showData() {
>>   var data = this.responseText;
>>   document.getElementById('result').innerHTML = data; }
>> </script> </body> </html> ============================================
>>
>> Garrett
>> > -a
>> >
>> >>
>> [snip "-----Original Message-----"]
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message