473,722 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 = saveTargetToAdd ress.Text;
string postData = textOutput.Text ;

try
{
System.Net.WebC lient myWebClient = new System.Net.WebC lient();

myWebClient.Upl oadFile(uriStri ng,"POST","C:\\ Shared\\XML\\su bflowhandler.xm l
");
}
catch (Exception Ex)
{
MessageBox.Show (Ex.Message);
}

Please help !!!!

Thank You very much in advance.
PS:
Error : org.apache.comm ons.fileupload. FileUploadExcep tion: Processing of
multipart/form-data request failed. Stream ended unexpectedly
Nov 16 '05 #1
6 12244
Have you included the proper length like .content length = sizeof(data)?
Nov 16 '05 #2
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 !

"Joep" <St***@DeStoep. nl> wrote in message
news:41******** *************** @news.xs4all.nl ...
Have you included the proper length like .content length = sizeof(data)?

Nov 16 '05 #3
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


Nov 16 '05 #4
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="subfl owhandler.xml"
<!-- this is the information which you are gonna get it from each
subflow(msvis
<classname>aJav aClassName</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:\bo ot.ini"
Content-Type: application/octet-stream

[boot loader]
timeout=30
default=multi(0 )disk(0)rdisk(0 )partition(2)\W INNT
[operating systems]
multi(0)disk(0) rdisk(0)partiti on(2)\WINNT="Mi crosoft Windows 2000
Professional" /fastdetect
Compute
-----------------------------7d41112770e48--



"Joep" <St***@DeStoep. nl> wrote in message
news:41******** *************** @news.xs4all.nl ...
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

Nov 16 '05 #5
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="subfl owhandler.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

"genc ymeri" <ge********@hot mail.com> wrote in message
news:eO******** *****@TK2MSFTNG P12.phx.gbl...
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 = saveTargetToAdd ress.Text;
string postData = textOutput.Text ;

try
{
System.Net.WebC lient myWebClient = new System.Net.WebC lient();

myWebClient.Upl oadFile(uriStri ng,"POST","C:\\ Shared\\XML\\su bflowhandler.xm l ");
}
catch (Exception Ex)
{
MessageBox.Show (Ex.Message);
}

Please help !!!!

Thank You very much in advance.
PS:
Error : org.apache.comm ons.fileupload. FileUploadExcep tion: Processing of
multipart/form-data request failed. Stream ended unexpectedly

Nov 16 '05 #6
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="subfl owhandler.xml"
<!-- this is the information which you are gonna get it from each
subflow(msvis
<classname>aJav aClassName</classname>p NameU="Handler" ID="3">
-----------------------8c67e9cc5ff7206
but the end does not have the last two dashes. Don;t know why.



"Sherif ElMetainy" <el************ *@wayout.net.NO SPAM> wrote in message
news:er******** ******@TK2MSFTN GP10.phx.gbl...
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="subfl owhandler.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

"genc ymeri" <ge********@hot mail.com> wrote in message
news:eO******** *****@TK2MSFTNG P12.phx.gbl...
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 = saveTargetToAdd ress.Text;
string postData = textOutput.Text ;

try
{
System.Net.WebC lient myWebClient = new System.Net.WebC lient();

myWebClient.Upl oadFile(uriStri ng,"POST","C:\\ Shared\\XML\\su bflowhandler.xm l
");
}
catch (Exception Ex)
{
MessageBox.Show (Ex.Message);
}

Please help !!!!

Thank You very much in advance.
PS:
Error : org.apache.comm ons.fileupload. FileUploadExcep tion: Processing of
multipart/form-data request failed. Stream ended unexpectedly


Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
942
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred during a webclient request" .._Hresult = "-2146233079" .._COMPlusExceptionCode ="-532459699" Sorry I don't have the whole error, but this seems to be the only pertinent
3
15091
by: Michael Fields | last post by:
I have a problem with the WebClient and uploading a file to a web server. The stream object returned from the WebClient.OpenWrite menthod throws a timeout exception when using this method on computers w/ low bandwith ( < = 256 kbs). The exception occurs when I call the Stream.Close method. Here is the code: WebClient client = new WebClient(); Stream postStream = client.OpenWrite(uri,"PUT"); postStream.Write(buffer, 0, buffer.Length);...
6
13297
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
13
4315
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
3
7580
by: Manuel | last post by:
I have an asp page ("test.asp") that presents the data it receives from a post.When I try the following code, test.asp doesn't return the values (supposedly) posted to it. If I make a web page with a form and the values, test.asp reports them fine. ---------------------------- Dim thePost As String = "Variable1=Value1&Variable2=Value2&Variable3=Value3" Dim thePage As Byte() Dim MyWebClient As New System.Net.WebClient
2
5970
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
1
1320
by: Chris Dunaway | last post by:
I am using the following code to test an .aspx page which has no presentation and only a handler for the Page_Load event. I am using this code to POST the contents of an .xml file to the .aspx page. The page received the file just find and uses Response.Write to send back a response to indicate it received the file. I am at a loss to understand how to get this response back from the WebClient.
0
1467
by: natzol | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST - Webclient=================================
4
12708
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST - Webclient=================================
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.