用VB下载网页内容

时间:2015-01-24 12:36:17

标签: vb.net

我正在使用Visual Basic 2010 Express并找到了一种读取文件的方法:

Dim byter = My.Computer.FileSystem.ReadAllBytes(“C:/ Documents and Settings / textfile.txt”)

如果我想阅读网站内容,我可以做类似的事情吗?

1 个答案:

答案 0 :(得分:0)

尝试类似:

  Dim uri as New Uri("http://thewebsite")
  Dim request as HttpWebRequest = HttpWebRequest.Create(uri)
  request.Method = WebRequestMethods.Http.Get
  Dim response As HttpWebResponse = request.GetResponse()
  Dim reader As New StreamReader(response.GetResponseStream())
  Dim webpageContents As String = reader.ReadToEnd()
  response.Close()