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.
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.
Re: Got To Webpage without using webbrowser control?
Quote:
Originally Posted by
Half
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?
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.