Skip to content

Instantly share code, notes, and snippets.

@christherama
Created May 13, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christherama/4b3d777607bdaeef3dbb to your computer and use it in GitHub Desktop.
Save christherama/4b3d777607bdaeef3dbb to your computer and use it in GitHub Desktop.
Visual Basic function to fetch a response from a web server
''' <summary>
''' Fetches the response from a website or server, with the provided URL
''' </summary>
Public Shared Function HttpGet(ByVal url As String) As String
' Create the HTTP request
Dim req As HttpWebRequest = HttpWebRequest.Create(url)
' Open a connection (stream) using the request
Dim stream As Stream = req.GetResponse.GetResponseStream()
' Create an object (StreamReader) to read from the stream
Dim sr As StreamReader = New StreamReader(stream)
' Read to the end of the stream
Dim response As String = sr.ReadToEnd()
' Close the stream
stream.Close()
' Return the response
Return response
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment