Click to See Complete Forum and Search --> : HttpWebResponse prolem, not releasing resources


dky1e
September 26th, 2002, 11:13 AM
Hi,

I created a class that reads the contents of a webpage based on the response from the server, here's the vb.net code:


Dim wrq As HttpWebRequest
Dim wres As HttpWebResponse
Dim sr As StreamReader

Dim s As Stream

wrq = CType(WebRequest.Create(url), HttpWebRequest)

Try
wres = CType(wrq.GetResponse(), HttpWebResponse)
sr = New StreamReader(wres.GetResponseStream())
strResponse = sr.ReadToEnd()
Finally
sr.Close()
wres.Close()
End Try


The problem is when the url is invalid then the streams aren't closed properly.