Teemee Tang

Teemee Tang

  • NA
  • 111
  • 10.4k

Error uploading image (in bytes) to a HTTP File server

Jun 21 2018 12:12 AM
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";
byte[] ImageData = System.IO.File.ReadAllBytes(image);
Uri _uri = new Uri(@"http://XXX.XXX.XX.X:8080/MyHTTPFileServer/helloX2.pdf");
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
byte[] responseArray = client.UploadData(_uri, "POST",ImageData);
string x = Encoding.ASCII.GetString(responseArray);
client.Dispose();

Answers (1)