DEWebWorks
asked on
System.IO.IOException: Cannot close stream until all bytes are written when sending webrequest
I am trying to send a web request but am getting the following error:
"System.IO.IOException: Cannot close stream until all bytes are written."
on the following line
myWriter.Close()
Here is my code snippet
objRequest = CType(WebRequest.Create(po st_url), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = 54
objRequest.ContentType = "application/x-www-form-ur lencoded"
objRequest.Headers("Author ization") = "BASIC " & authorization_string
post_string = "&command=requestnewpasswo rd&applica tion=netco nnect"
' post data is sent as a stream
myWriter = Nothing
myWriter = New StreamWriter(objRequest.Ge tRequestSt ream())
myWriter.Write(post_string )
myWriter.Close()
Anyone have any ideas how to fix this?
"System.IO.IOException: Cannot close stream until all bytes are written."
on the following line
myWriter.Close()
Here is my code snippet
objRequest = CType(WebRequest.Create(po
objRequest.Method = "POST"
objRequest.ContentLength = 54
objRequest.ContentType = "application/x-www-form-ur
objRequest.Headers("Author
post_string = "&command=requestnewpasswo
' post data is sent as a stream
myWriter = Nothing
myWriter = New StreamWriter(objRequest.Ge
myWriter.Write(post_string
myWriter.Close()
Anyone have any ideas how to fix this?
Try calling the Flush before close.
Maybe u could add a try and call the close method in finally block
ASKER
I tried adding myWriter.Flush() just before the close line, but it didn't change anything.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the answer elsewhere, but wanted to show the answer for others that might encounter this same problem.