Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

VB.NET : Login to a website programmatically

  • 21-10-2003 11:38am
    #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,761 ✭✭✭✭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,035 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