Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
' 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