User-1836216065 posted
Hi,
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:
With WebRequest
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
.PreAuthenticate = False
.AuthenticationLevel = Security.AuthenticationLevel.None
End With
If FileSize > 0 Then
WebRequest.ContentLength = FileSize
End If
Try
RequestStream = WebRequest.GetRequestStream()
StreamWriter = New StreamWriter(RequestStream)
StreamWriter.Write(strDataToPost)
StreamWriter.Flush()
RequestStream.Flush()
StreamWriter.Close()
RequestStream.Close()
Catch ex As Exception
RTResponse(0) = -1
RTResponse(1) = ex.Message
End Try
I have also tried amending the timeout, but it makes no difference.
Any help would be greatly appreciated.