streamwriter

G

Guest

he following code times out at the "rsp = req.GetResponse()".I am under the
impression you could carry on all day sending and getting responses but no if
you dont have a close it doesnt work. All documentation shows example of 1
read and write so I have no idea why this doesn't work.If I add a close after
the write the timeout goes away and I receive data from the ASPX app on the
server as expected.

Dim req As WebRequest
Dim rsp As WebResponse
Try
' Setup the WebRequest instance
req =
WebRequest.Create("http://localhost/BestSwitch/Bestswitch.aspx")
' Use POST since we're sending data
req.Method = "POST"
'Testing
Dim sw As New StreamWriter(req.GetRequestStream())
sw.Write("hello")
sw.Flush()
******************* add a sw.close here and the timeout goes away. me
non comprehendo


rsp = req.GetResponse() ****************************** Timeout
if no sw.close
Dim sr As New StreamReader(rsp.GetResponseStream())
Dim Recv As String = sr.ReadToEnd()
MsgBox(Recv)


sw.Write("gotcha") '****************** Can't write to closed
text writer if the sw.close is put in above
sw.Close()

rsp = req.GetResponse()
Recv = sr.ReadToEnd()
MsgBox(Recv)
sr.close()

Much appreciated if someone could comment or cast any light on this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top