Created
May 13, 2015 16:29
-
-
Save christherama/4b3d777607bdaeef3dbb to your computer and use it in GitHub Desktop.
Visual Basic function to fetch a response from a web server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' <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