sarpay
4/10/2013 - 11:23 PM

[.net] [.vb] [webrequest] [webresponse] [stream] [xmlhttp] get html from an external source and convert into a string using XMLHTTP

[.net] [.vb] [webrequest] [webresponse] [stream] [xmlhttp] get html from an external source and convert into a string using XMLHTTP

Private Function GetExternalHTML(ByVal sSourceURL As String)

  Dim request As WebRequest = WebRequest.Create(sSourceURL)
  Dim response As WebResponse = request.GetResponse()
  Dim responseStream As Stream = response.GetResponseStream()
  Dim data(1023) As Byte
  Dim count As Integer
  Dim strTotal As New StringBuilder()
  Dim myencoding As New ASCIIEncoding()

  While True
    count = responseStream.Read(data, 0, 1024)
    If count <= 0 Then
      Exit While
    End If
    strTotal.Append(myencoding.GetString(data))
  End While

  responseStream.Close()

  GetExternalHTML = strTotal.ToString

End Function