今天有个朋友问起,于是拿以前写的代码给他看,并记录一下,方便以后查阅。
VB.NET:
Dim str As String
Dim path As String
'获取请求流
Dim sm As System.IO.Stream
Dim sr As System.IO.StreamReader
Dim getre As System.Net.HttpWebRequest
Dim getrp As System.Net.HttpWebResponse
Dim url As New Uri('http://www.163.com')
getre = System.Net.HttpWebRequest.Create(url)
getrp = getre.GetResponse
sm = getrp.GetResponseStream
sr = New System.IO.StreamReader(sm, System.Text.Encoding.GetEncoding("gb2312"))
str = sr.ReadToEnd
getrp.Close()
sm.Close()
sr.Close()
'获取结束