相比:
Using Response As WebResponse = Request.GetResponse
Using reader As StreamReader = New StreamReader(Response.GetResponseStream)
strWebResponse = reader.ReadToEnd
End Using
End Using
和:
Dim xmldoc As XmlDocument = new XmlDocument
xmldoc.Load(Request.GetResponse().GetResponseStream)
在第一个例子中,Response
显然是设置在第二个End Using
语句处。
在第二个例子中,WebResponse
创建的对象什么时候Request.GetResponse()
被释放?
是否应该将第二个示例重写如下以确保WebResponse
正确处理?
Dim xmldoc As XmlDocument = new XmlDocument
Using Response As WebResponse = Request.GetResponse
xmldoc.Load(Response.GetResponseStream)
End Using