Last post Sep 02, 2010 05:41 AM by jechojekov
Feb 10, 2009 07:14 AM|tomwest|LINK
I have a testing platform that allows data to be posted to a real time collection system. It uses the StreamWriter object to send both HTTP and XML formats,
It works fine, but there is a new request to submit uploaded files. This again works fine, unless the files are over 70k (we need to test upto 3MB). If it is over 70k, the response is
the content-length too big.
I have changed it so that the content-length is now set dynamically, dependant on the size of the file uploaded. However, when the StreamWriter.Close() runs, the execption
The request was aborted: The request was canceled. is generated, with the InnerException
Cannot close stream until all bytes are written.
From what I have found on the web, the solution is use StreamWriter.Flush(), but this code is already in place.
Code is as follows:
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
.PreAuthenticate = False
.AuthenticationLevel = Security.AuthenticationLevel.None
If FileSize > 0 Then
WebRequest.ContentLength = FileSize
RequestStream = WebRequest.GetRequestStream()
StreamWriter = New StreamWriter(RequestStream)
Catch ex As Exception
RTResponse(0) = -1
RTResponse(1) = ex.Message
I have also tried amending the timeout, but it makes no difference.
Any help would be greatly appreciated.
Feb 10, 2009 10:14 AM|DkUltra|LINK
A person could try streamwriter.dispose
Also, naming the variables the same name as the class could be causeing the error
use strWriter = new streamWriter
Hope this helps
Sep 02, 2010 05:41 AM|jechojekov|LINK
Increase the value of "HttpWebRequest.Timeout". This value restricts the total time within which the reqest must complete.