Results 1 to 4 of 4

Thread: Got To Webpage without using webbrowser control?

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Got To Webpage without using webbrowser control?

    Got To Webpage without using webbrowser control?
    If so, how would i read / get the html of this page? I can do this now with a webbrowser control, but just looking for a quicker way.

    I've seen this online below.

    Imports System
    Imports System.IO
    Imports System.Net
    Module Module1
    Sub Main()
    'Address of URL
    Dim URL As String = http://www.c-sharpcorner.com/default.asp
    Dim request As WebRequest = WebRequest.Create(URL)
    Dim response As WebResponse = request.GetResponse()
    Dim reader As StreamReader = New StreamReader(response.GetResponseStream())Dim str As String = reader.ReadLine()
    o While str.Length > 0
    Console.WriteLine(str)
    str = reader.ReadLine()
    Loop
    End Sub
    End Module


    However, if the site requires you to log in first, can you then do a webrequest call, and have it use he webbrowsers controls cache to see that you've already logged in, and not request you to log in?
    Hope this makes sense.
    Last edited by joefox; Nov 29th, 2010 at 02:38 PM.

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Got To Webpage without using webbrowser control?

    You don't go to a page; you ask a computer to send you a bunch of instructions, your browser receives them and executes them. If you want to see a webpage you need to execute its instructuions hence you need a browser.

    If you want only these instructions aka the source code you can use the WebClient to download that. It's easy but not very flexible because it lacks timeout settings and your app may hung unless you use it asynchronously.

    If you want to be able to set timeouts, use paired http webrequest and http webresponse. They are also useful for doing some action like clicking a button on that page because you have to send the server the same reply as if you actually clicked that button but without loading the page first.
    VB 2005, Win Xp Pro sp2

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Got To Webpage without using webbrowser control?

    Quote Originally Posted by Half View Post
    You don't go to a page; you ask a computer to send you a bunch of instructions, your browser receives them and executes them. If you want to see a webpage you need to execute its instructuions hence you need a browser.

    If you want only these instructions aka the source code you can use the WebClient to download that. It's easy but not very flexible because it lacks timeout settings and your app may hung unless you use it asynchronously.

    If you want to be able to set timeouts, use paired http webrequest and http webresponse. They are also useful for doing some action like clicking a button on that page because you have to send the server the same reply as if you actually clicked that button but without loading the page first.
    any example of this anywhere?
    Ive seen how you can send the requests etc. but my problem is, the site requires you to login, so can this login be done via just a webrequest?

  4. #4
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Got To Webpage without using webbrowser control?

    Yes it can. The instructions to the server are usually send via the POST method, which contains the data the server need to service your request. In the case of logging in that would be your username and and password (or its hash value).

    The POST is just a string but it is different for each application. This means you have to construct it yourself. The good news is when you know how the post for one platform is constructed you can use it to login to all its brethren.

    To know exactly what the post contains you need a packet sniffer such as fiddler. You start it then log in normally via webbrowser and check what the sniffer outputs. It will show you exactly what the browser is doing. From there you just need to emulate it.

    Here is an example. Note that the postData variable specified there will not work for logging on to a vBulletin forum such as this one. You have to find it yourself as described above or use google for specific post strings.
    VB 2005, Win Xp Pro sp2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width