C# webclient, uploading a file Error :// Error : Stream ended unexpectedly

  • Thread starter Thread starter genc ymeri
  • Start date Start date
G

genc ymeri

Hi,
We are struggeling to upload a file through a C# webClient into JBoss web
server. Meanwhile we are able to upload a file from the webserver itself.
The problem is only with C# webClient . The code is pretty simple.


string uriString = saveTargetToAddress.Text;
string postData = textOutput.Text;

try
{
System.Net.WebClient myWebClient = new System.Net.WebClient();

myWebClient.UploadFile(uriString,"POST","C:\\Shared\\XML\\subflowhandler.xml
");
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}



Please help !!!!

Thank You very much in advance.


PS:
Error : org.apache.commons.fileupload.FileUploadException: Processing of
multipart/form-data request failed. Stream ended unexpectedly
 
No ! What object has these properties ? Any tip how or where to use it
????? I'm using the google but we are not getting it.

Thanks a lot in advance !
 
I might be looking in the wrong direction but nevertheless, WebClient has a
collection of Headers. A Header can be accessed something like so,
Headers["someHeader"]. WebClient should set content length itself when
applicable. Content type header value could be another reason. I don't know
apache but it thinks it gets multipart/form-data and it is not able to
determine the proper length of the data. If connectivity is not the problem
than I would check these headers.

HTH
 
Actually, we debuged it and we noticed that the headers are OK but the
terminator is missing (Terminator is composed of 2 dashes 0x2D). We compared
the output of the EchoServer from uploading it through TomCat and from C#
webClient and we did see that the termination was missing in webCLient
upload.

Any idea how to set the terminator or to fix this ??????

Any help very much will be apprciated !!!!!


<! this echo came from webClient
EchoServer: got connection from 127.0.0.1
CWU: POST / HTTP/1.1
CWU: Content-Type: multipart/form-data;
boundary=---------------------8c67e9cc5f
f7206
CWU: Content-Length: 446
CWU: Expect: 100-continue
CWU: Connection: Keep-Alive
CWU: Host: localhost:8088
CWU:
CWU: -----------------------8c67e9cc5ff7206
Content-Disposition: form-data; name="file"; filename="subflowhandler.xml"
<!-- this is the information which you are gonna get it from each
subflow(msvis
<classname>aJavaClassName</classname>p NameU="Handler" ID="3">
-----------------------8c67e9cc5ff7206
<! this echo came from webClient>




<! this echo came from TomaCat>

POST / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
application/x-shockwave-flash, */*
Referer: http://localhost:8080/examples/jsp/BrowsePage.jsp
Accept-Language: en-us
Content-Type: multipart/form-data;
boundary=---------------------------7d41112770e48
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR
1.1.4322)
Host: localhost:8088
Content-Length: 643
Connection: Keep-Alive
Cache-Control: no-cache

-----------------------------7d41112770e48
Content-Disposition: form-data; name="xpdl"; filename="C:\boot.ini"
Content-Type: application/octet-stream

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(2)\WINNT
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINNT="Microsoft Windows 2000
Professional" /fastdetect


Compute
-----------------------------7d41112770e48--
 
Hello

I see from the error message that the server is expecting a
multipart/form-data content to be uploaded. So instead the server finds just
xml data so it can't parse it. Change your code so that the data uploaded to
the server looks like this:

--abcdefghi
content-disposition: form-data; name="myFile"; filename="subflowhandler.xml"
content-type: text/xml;charset=utf-8
content-transfer-encoding: 8Bit

<data>
xml data goes here
</data>

--abcdefghi--

This example assumes that the page posing to the server has an input file
with name "myFile"
For more information read the RFC2388 at
http://www.faqs.org/rfcs/rfc2388.html

Best regards,
Sherif
 
Thanks for relpying. The server is getting a multipart/form-data content and
here is what Tomcat is getting

<! this echo came from webClient
EchoServer: got connection from 127.0.0.1
CWU: POST / HTTP/1.1
CWU: Content-Type: multipart/form-data;
boundary=---------------------8c67e9cc5f
f7206
CWU: Content-Length: 446
CWU: Expect: 100-continue
CWU: Connection: Keep-Alive
CWU: Host: localhost:8088
CWU:
CWU: -----------------------8c67e9cc5ff7206
Content-Disposition: form-data; name="file"; filename="subflowhandler.xml"
<!-- this is the information which you are gonna get it from each
subflow(msvis
<classname>aJavaClassName</classname>p NameU="Handler" ID="3">
-----------------------8c67e9cc5ff7206


but the end does not have the last two dashes. Don;t know why.
 
Back
Top