INet equivalent in vb.net

  • Thread starter Thread starter Chris Smith
  • Start date Start date
Hello Group,
All I wanna do is to get the contents of a web page and
display it in my application. VB 6.0 has the INet control. How do I do it
using VB.NET/

Thanks for the help,
Chris.
 
Hi Chris,

Thanks for using Microsoft MSDN Managed Newsgroup. My name is Peter, and I
will be assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to get the content of a
web page in VB.NET.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think the WebClient class will be a good choice. The link below also
include a sample.
WebClient.DownloadData Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemnetwebclientclassdownloaddatatopic.asp

Or you may try to use the HttpWebRequest class which will give more
flexible function.
HttpWebRequest Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemnethttpwebrequestclasstopic.asp
<sample>
Imports System.Net
Imports System.Text
Imports System.IO
Module Module2
Public Sub Main()
Dim url As String = "http://www.google.com"
' Creates an HttpWebRequest for the specified URL.
Dim myHttpWebRequest As HttpWebRequest =
CType(WebRequest.Create(url), HttpWebRequest)
' Sends the request and waits for a response.
Dim myHttpWebResponse As HttpWebResponse =
CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Calls the method GetResponseStream to return the stream
associated with the response.
Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
' Pipes the response stream to a higher level stream reader with
the required encoding format.
Dim readStream As New StreamReader(receiveStream, encode)
Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "Response
stream received")
Dim read(256) As [Char]
' Reads 256 characters at a time.
Dim count As Integer = readStream.Read(read, 0, 256)
Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
While count > 0
' Dumps the 256 characters to a string and displays the string
to the console.
Dim str As New [String](read, 0, count)
Console.Write(str)
count = readStream.Read(read, 0, 256)
End While
Console.WriteLine("")
' Releases the resources of the Stream.
readStream.Close()
' Releases the resources of the response.
myHttpWebResponse.Close()
End Sub
End Module
</sample>

Please try the link above and let me if that answer your question.
If you have any concern on this question, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top