Recent VB login Code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danleeds
    Junior Member
    • Dec 2018
    • 2

    #1

    Recent VB login Code?

    Does anyone have any sample code which I could utilise to login to the Betfair API?

    Wanting to create a windows form application

    Just getting started with VB and struggling to find any samples online.
  • Bascoe
    Member
    • Sep 2018
    • 42

    #2
    Code:
    Imports System.Net
    
    Public Class BfLogin
    
        Dim loginUrl As String = Nothing
    
        Public Sub New()
            loginUrl = "https://identitysso.betfair.com/api/login?username={0}&password={1}&login=true&redirectMethod=POST&product=home.betfair.int&url=https://www.betfair.com/"
        End Sub
    
    
        Public Function LoginSession(username As String, password As String) As String
            Dim ssoid As String = [String].Empty
            Dim info As String()
            Dim sessToken As String = ""
            Try
                Dim uri As String = String.Format(loginUrl, username, password)
                Dim myRequest As HttpWebRequest = DirectCast(WebRequest.Create(uri), HttpWebRequest)
                myRequest.Method = "POST"
                myRequest.Timeout = 5000
                Dim thePage As WebResponse = myRequest.GetResponse()
                info = thePage.Headers.GetValues("Set-Cookie")
                Dim i As Integer = 0
                System.Net.ServicePointManager.Expect100Continue = False
                While ssoid = [String].Empty AndAlso i < info.Length
                    If info(i).Contains("ssoid=") Then
                        ssoid = info(i)
                    End If
                    i += 1
                End While
                'This returns
                sessToken = ssoid.Replace("ssoid=", "") 'Dump front string
                sessToken = sessToken.Replace("; Domain=.betfair.com; Path=/", "") 'dump rear string
            Catch ex As System.Exception
                'Logger.writeErrorLogEntry("Exception at LoginForm.LoginSession: " & ex.ToString())
                'MessageBox.Show("Exception at LoginForm.LoginSession: " & ex.ToString())
            End Try
            Return sessToken '~~> Should work ok if Login a success
        End Function 'Session Token and Login
    End Class

    Comment

    • danleeds
      Junior Member
      • Dec 2018
      • 2

      #3
      Thank you. This gives me a starting point for my application.

      Comment

      • LetsGo
        Senior Member
        • Oct 2018
        • 112

        #4
        In my experience the best way to develop a vb.net application is to use the Betfair c# sample program and reference it from your vb.net code.
        In Visual Studio you can have both vb.net and c# projects.
        The Betfair c# sample is a working version and you don't have to change the code from within vb.net, you just add a reference .

        In vb.net you would have the imports from the c# sample.

        Imports Aping_cs
        Imports Aping_cs.Json
        Imports Aping_cs.TO
        Imports System.Threading.Tasks
        Imports Betfair.ESAClient.Cache
        Imports Betfair.ESAClient.Auth
        Imports Betfair.ESAClient
        Imports Betfair.ESASwagger.Model
        Imports Betfair.ESASwagger.Model.MarketDataFilter


        Add a reference to Betfair.ESAClient (the c# sample) from your vb.net project.

        To place a bet you would call:-
        Public bfa As New CBetfairApi_ng (the c# code)

        bfa.PlaceBet_Api_ng(...)



        Comment

        Working...
        X