Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VB.NET : Login to a website programmatically

  • 21-10-2003 12:38PM
    #1
    Registered Users, Registered Users 2 Posts: 450 ✭✭


    I need to parse an online Web page to retrieve certain figures. I have no problem doing this using the Net.Webclient on regular, unprotected pages.

    However, the page I want to access requires username/password authentication for each session. This is where I need help.

    Any ideas on where I should start would be much appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 14,762 ✭✭✭✭Winters


    Are you looking for a VBscript login?

    Are you going to be using a database login? or a gerenic usename and password for all?

    With the database login you need to create a database connection and in the SQL have the following:

    Select 'Username' AND 'Password' WHERE Username = '"& Request.Form("username_login") &"' AND Password = '"& Request.Form("password_login")

    Then you have to make sure you dont get an End OF Form. If you get an end of form it means there is no username or password matching that description:

    If EOF is true and BOF is true Then
    Response.Write("Error bad username and password")
    Else
    Response.Write("Correct Username and Password")
    ' ** add what other stuff you need in here like sessions, cookies and the like
    End If.

    Actucully, thats just VB and not VB.net but it works for me and is just as good. If this is no help .. sorry. :)


  • Closed Accounts Posts: 202 ✭✭DSLinAbsentia


    You need to look at the authentication page you're parsing. If the form on the page uses GET, then you can auto authenticate by sending the credentials as part of the URL with a GET request, i.e.,

    if the form fields are name and pswd, then you could use the WebClient API with a URL or http://myurl/auth?name=XXX&pswd=YYYY" where the URL is formed programmatically.

    If the webpage uses POST, then you should create and customise a HTTP header prior to issuing a post request. I'm a Java head, it's easy with that, though I'm sure the .NET stuff has similar functionality.


  • Registered Users, Registered Users 2 Posts: 640 ✭✭✭Kernel32


    Look at the httpWebRequest class in the framework documentation, it can be found in your helpfile at ms-help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemnethttpwebrequestclasstopic.htm

    It should contain the funationality you request.


  • Moderators, Science, Health & Environment Moderators Posts: 9,220 Mod ✭✭✭✭mewso


    It's not too difficult to assign credentials to a web request:-
    Dim myReq As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create("http://www.boards.ie"), System.Net.HttpWebRequest)
    Dim cred As New System.Net.NetworkCredential("username", "password")
    myReq.Credentials = cred
    Dim myStream As System.IO.Stream
    myStream = myReq.GetResponse.GetResponseStream
    

    etc.


Advertisement