HttpWebRequest.Connection gets or sets the value of the Connection HTTP header.
Imports System.IO
Imports System.Net
Imports System.Text
Class HttpWebRequest_Connection
Shared Sub Main()
Dim myHttpWebRequest1 As HttpWebRequest = CType(WebRequest.Create("http://www.domain.com"), HttpWebRequest)
myHttpWebRequest1.KeepAlive = False
Dim myHttpWebResponse1 As HttpWebResponse = CType(myHttpWebRequest1.GetResponse(), HttpWebResponse)
Console.WriteLine(myHttpWebRequest1.Headers)
Dim streamResponse As Stream = myHttpWebResponse1.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
Console.Write(outputData)
count = streamRead.Read(readBuff, 0, 256)
End While
streamResponse.Close()
streamRead.Close()
myHttpWebResponse1.Close()
Console.WriteLine()
Dim myHttpWebRequest2 As HttpWebRequest = CType(WebRequest.Create("http://www.domain.com"), HttpWebRequest)
myHttpWebRequest2.Connection = "Close"
Dim myHttpWebResponse2 As HttpWebResponse = CType(myHttpWebRequest2.GetResponse(), HttpWebResponse)
myHttpWebResponse2.Close()
Console.WriteLine(myHttpWebRequest2.Headers)
End Sub
End Class
Related examples in the same category