Académique Documents
Professionnel Documents
Culture Documents
The Microsoft .NET Framework includes many useful classes for networking, including the
ability to make Web requests. This article demonstrates how to make a simple GET request to
retrieve a Web page from the Internet.
Requirements
The following list outlines the recommended hardware, software, network infrastructure, and
service packs that you will need:
Microsoft Windows 2000 Professional, Microsoft Windows Server 2003, Windows 2000 Server,
Windows 2000 Advanced Server, or Windows NT 4.0 Server
Microsoft Visual Studio .NET or Microsoft Visual Studio 2005
NOTE: If you are behind a proxy server, you will need either an internal Web address or static
proxy values (see steps 7 and 8) to test the code in this article.
wrGETURL.Proxy = myProxy
If you wish to just use whatever settings have been configured in Internet Explorer, you can do
that through the GetDefaultProxy static method of the WebProxy class.
wrGETURL.Proxy = WebProxy.GetDefaultProxy()
Now that your request is set up with the target URL and any applicable proxy information, you
can use it to obtain a Stream object corresponding to the response to your request.
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream()
After you have the response stream, you can treat it like any other stream (such as from
opening a text file) and read through its contents line by line or even all at once. The loop below
reads the stream one line at a time until the ReadLine method returns Nothing, outputting each
line to the console.
Dim objReader As New StreamReader(objStream)
Dim sLine As String = ""
Dim i As Integer = 0