I think you also need two newlines after the Content-Disposition. Try:
req.send('--DATA1215979532633\r\n'
+'Content-Disposition: form-data; name="name";\r\n\r\n'
+'a\r\n'
+'--DATA1215979532633--');
-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
|