Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to upload an image (in bytes) from a HTTP server. I am encountering an error "An existing connection was forcibly closed by the remote host" when using the code below. DownloadData and UploadFile methods are working. Please help.

string image = @"C:\.....\helloX2.pdf";<br />
byte[] ImageData = System.IO.File.ReadAllBytes(image);<br />
Uri _uri = new Uri(@"http://XXX.XXX.XX.X:8080/MyHTTPFileServer/helloX2.pdf");<br />
WebClient client = new WebClient();<br />
client.Credentials = CredentialCache.DefaultCredentials;<br />
byte[] responseArray = client.UploadData(_uri, "POST",ImageData);<br />
string x = Encoding.ASCII.GetString(responseArray);<br />
client.Dispose();


What I have tried:

DownloadData and UploadFile methods are working.
Posted
Comments
Jochen Arndt 21-Jun-18 4:52am    
UploadData() is not intended for uploading files and will definitely not work with an URI pointing to a PDF file.

Just use UploadFile().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900