Advertisement
4_2005-2006 Internet/ Browsers/ HTML #162365

Downloading HTTP with VB.NET

Explains how to download http with VB.NET, includes a simple example.

AI

สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ซอร์สโค้ด
original-source
<br><br>
Downloading using HTTP with VB.NET is a fairly simple task. It really only takes four steps:<br><br>
1 - Use the <i>Create</i> method of the <i>System.Net.WebRequest</i> class to specify the web page. This method will return a <i>HttpWebRequest</i> if the web page is http://, it will return a <i>FileWebRequest</i> if the web page is file://.<br>
2 - Use the <i>GetResponse</i> method of the <i>WebRequest</i> object and return a <i>WebResponse</i> object for the web page.<br>
3 - Create a <i>StreamReader</i> or <i>BinaryReader</i> depending on the type of data to be downloaded.<br>
4 - The specifics that you need to perform on the stream.<br><br>
 
The following example simply displays the html of a web page -<br><br>
 
First, import <i>System.Net</i> and <i>System.IO</i> <br><br>
 
<pre>
Public Module Download
 Public Sub Main()
 Dim PgReq As HttpWebRequest = CType(WebRequest.Create(http://www.yahoo.com/index.html), HttpWebRequest)
 Dim PgResp As WebResponse = PageRequest.GetResponse()
 Dim sr As New StreamReader(PgResp.GetResponseStream())
 Dim Pg As String = sr.ReadToEnd()
 sr.Close()
 Console.Write(Pg)
 Console.ReadLine()
 End Sub
End Module
</pre>
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine