Programming Tutorials

How to read URL Content through VB.net code

By: Issac in VB.net Tutorials on 2009-02-21  

When we want to read content of an HTML page from a remote webserver, in vb.net we are using WebRequest, WebResponse. WebResponse return a StreamReader and we can get the content from StreamReader.

vb.net_read_url.JPG

Imports System.Net
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim inStream As StreamReader
        Dim webRequest As WebRequest
        Dim webresponse As WebResponse
        webRequest = webRequest.Create(TextBox1.Text)
        webresponse = webRequest.GetResponse()
        inStream = New StreamReader(webresponse.GetResponseStream())
        TextBox2.Text = inStream.ReadToEnd()
    End Sub
End Class

You have to write this code in the button click event so that if we click the Get Page button we will get the URL content.





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)