1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

VB.NET: Automatic login to .NET website.

Discussion in 'Programming' started by camjohnson95, Dec 29, 2008.

  1. #1
    Im from Australia and i'm trying to create an app that will login to Australia's TAB website (tab.com.au) and place a bet. The website seems to be have been created in ASP.NET but there is a lot of javascript and i can't work out how i should go about this..
    I know how to transmit and receive the http headers but am not sure what needs to be sent and receive (as it is a fairly complex and secure system).
    I've used an Http packet sniffer to see what headers the browser is sending and receiving and still can't seem to work it out... does anyone have any ideas or is there is anyone who has done something similar?

    I did manage to login and place a bet using the WebBrowser control by filling in the textboxes with code and then creating a 'click' event on the login button, but when it submits the bet it only works sometimes and otherwise comes up with a 'Server error'... i have no idea why this happens, my only guess is that it does that when there is too many requests from the same IP (within a specific timeframe) and it blocks that IP for a certain amount of time (as i found yahoo search does).

    Any advice would be appreciated.
    Here is the code i am currently using.. it may be of use to someone:
    
    Dim whereami as Integer
    Dim loggedin as Boolean
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            whereami = 0
            loggedin = False
            WebBrowser1.Navigate("http://www.tab.com.au/racing/default.aspx?State=1")
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            If whereami = 0 Then
                Dim but1 As Object
                WebBrowser1.Document.GetElementById("DisplayTopMenu_DisplayTopNav1_TextboxLogin").SetAttribute("value", "123456")
                WebBrowser1.Document.GetElementById("DisplayTopMenu_DisplayTopNav1_TextboxPassword").SetAttribute("value", "mypassword")
                but1 = WebBrowser1.Document.GetElementById("DisplayTopMenu_DisplayTopNav1_ButtonLogin").DomElement
                but1.Click()
                whereami = whereami + 1
                Exit Sub
            ElseIf whereami = 1 Then
                WebBrowser1.Navigate("http://www.tab.com.au/ExpressBet/Standard/Default.aspx?State=1")
                whereami = whereami + 1
                Exit Sub
            ElseIf whereami = 2 Then
                Dim dom As Object
                dom = WebBrowser1.Document.DomDocument
                dom.Links(1).Click()
                whereami = whereami + 1
                loggedin = True
                Exit Sub
            End If
        End Sub
    
        Sub placebets(ByVal batchbets As String)
            Dim olddate As Date
            Dim procs() As Process
            WebBrowser1.Document.GetElementById("BvTextArea").InnerText = batchbets
            ClickLink(WebBrowser1.Document.DomDocument, "SUBMIT BATCH")
            olddate = Now
    'Wait five seconds until the confirmation window opens
            Do
                Application.DoEvents()
            Loop Until DateDiff(DateInterval.Second, olddate, Now) >= 5 Or DateDiff(DateInterval.Second, olddate, Now) <= -5
            procs = Process.GetProcesses()
    'close confirmation window
            For i = 0 To procs.Length - 1
                If procs(i).MainWindowTitle = "https://www.tab.com.au/?State=1 - BetReceiptSummary - Windows Internet Explorer" Then
                    procs(i).CloseMainWindow()
                    Exit For
                End If
            Next
        End Sub
    
        Sub ClickLink(ByVal doc As Object, ByVal LinkText As String)
            For i = 0 To doc.Links.Length - 1
                If LTrim(RTrim(doc.Links(i).OuterText)) = LinkText Then
                    doc.Links(i).Click()
                    Exit For
                End If
            Next i
        End Sub
    
    Code (markup):
    If you use the Aus TAB website, this will probably make sense to you more then most people, but you can use code similar to this to login to any website. If it isn't obvious WebBrowser1 is a webbrowser control.

    Any advice on why i may get the 'server error' or how to do this using only HTTP Requests, please let me know..
     
    camjohnson95, Dec 29, 2008 IP
  2. brian65

    brian65 Active Member

    Messages:
    1,172
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #2
    If the IP is getting problems due to too many requests, I'm not sure that HTTP requests will be any better.

    One thing that might be affecting your code is the state of the webbrowser control. Read this webbrowser documentcompleted info to find out more. Sorry not to be of more help.
     
    brian65, Dec 29, 2008 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    it isn't the webbrowser itself.. when a bet is placed a confirmation window is launched. This window most of the time displays 'Server Error'.. i might have to try it again, maybe there was an actual error on the server when i was testing it, or i tested it too much, which blocked me. I know yahoo says the same thing when you post too many requests too quickly.

    But i would prefer to use direct requests as opposed to webbrowser...
     
    camjohnson95, Dec 29, 2008 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    That link is interesting... i have no problem with the code executing, just with the server response..
     
    camjohnson95, Dec 29, 2008 IP
  5. ztreewin

    ztreewin Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I realize this is over a year old, but I wondered if you ever found a solution?
    I'm using similar code to your sample, but C# - the problem seems to be when the connection tries to switch from http to https.
    I discovered if I open up IE manually and logon there, my program is able to make the SSL connection to submit bets, but of not, it just hangs, and then times out.
    Did you ever solve this?
    Would be very grateful for some clues if you did, or to bounce some ideas around if you are still interested in solve this yourself ;-)

    Thanks!
     
    ztreewin, Feb 22, 2010 IP