By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

HttpWebRequest webexception - The Request was aborted: The request was cancelled

P: 1

I'm trying to use HttpWebRequest to upload a 12Mb file to a remote server which sends a response xml string back.

I'm failing in this and receiving the following web exception-
The Request was aborted: The request was cancelled

my code is below. Can anyone tell me where I've gone wrong.
I'm out of my depth with this, not an area I know much about.

Expand|Select|Wrap|Line Numbers
  1. Private Function publishXML(ByVal uriString As String, ByVal sTransferFile As String) As Boolean
  2.         Dim FileInfo As New FileInfo(sTransferFile)
  3.         Dim uploadRequest As HttpWebRequest = CType(WebRequest.Create(uriString), HttpWebRequest)
  4.         uploadRequest.Method = WebRequestMethods.Http.Post
  5.         uploadRequest.ContentType = "multipart/form-data"
  6.         uploadRequest.ContentLength = FileInfo.Length
  7.         uploadRequest.Timeout = 10000  'timeout in milliseconds
  8.         Dim RequestStream As Stream = uploadRequest.GetRequestStream
  9.         Dim FileStream As FileStream = File.Open(sTransferFile, FileMode.Open)
  12.         Dim Buffer As Byte() = Encoding.UTF8.GetBytes(sTransferFile)
  13.         Dim bytesRead As Integer
  14.         While True
  15.             bytesRead = FileStream.Read(Buffer, 0, Buffer.Length)
  16.             If bytesRead = 0 Then
  17.                 Exit While
  18.             End If
  19.             RequestStream.Write(Buffer, 0, bytesRead)
  20.         End While
  22.         RequestStream.Close()
  23.         Dim myResponse As HttpWebResponse = CType(uploadRequest.GetResponse(), HttpWebResponse)
  24.         Dim readStream As New StreamReader(myResponse.GetResponseStream, Encoding.ASCII)
  25.         Dim responseString As String = readStream.ReadToEnd
  26.         Dim SW As StreamWriter = New StreamWriter("ResponseFolder" & My.Settings.responseFileName)
  27.         SW.Write(responseString)
  28.         SW.Flush()
  29.         SW.Close()
  31.     End Function

Greatly appreciate any help
May 3 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.