Sample VB.NET code for Navigation Data For Applications

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahn
    Junior Member
    • Jul 2011
    • 12

    #1

    Sample VB.NET code for Navigation Data For Applications

    Hi to all.

    I am trying to request the navigation menu in VB.NET and I am getting error 400 Bad request. Could someone send me a code for doing so?

    Code:
    Sub GetNavigatorManu(ByVal SessToken As String, Optional ByVal AppKey As String = "")
    
            Dim request As HttpWebRequest = Nothing
            Dim response As HttpWebResponse = Nothing
    
    
            Dim strResponseStatus As String = ""
            Try
                request = WebRequest.Create(New Uri("https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json"))
    
                request.Accept = "application/json"
                request.Method = "GET"
                request.KeepAlive = True
    
                'request.ContentType = "application/json"
                request.AutomaticDecompression = DecompressionMethods.GZip Or DecompressionMethods.Deflate
                ' request.AutomaticDecompression = DecompressionMethods.Deflate
                request.Headers.Add("Content-Encoding: gzip")
                '  request.Headers.Add("Accept-Encoding", "gzip,deflate")
                request.Headers.Add("X-Authentication", SessToken)
    
    
                request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8")
    
                If AppKey <> "" Then
                    request.Headers.Add("X-Application", AppKey)
                End If
                '~~> Get the response.
                response = request.GetResponse()
                '~~> Display the status below 
                strResponseStatus = "Status is " & CType(response, HttpWebResponse).StatusCode
    
            Catch ex As Exception
                MsgBox("CreateRequest Error" & vbCrLf & ex.Message)
            End Try
            MsgBox(strResponseStatus)
            '~~~Clean Up
    
        End Sub
  • betdynamics
    Junior Member
    • Sep 2010
    • 534

    #2
    I'm not too familiar with VB, but you could try the following:

    Code:
    Sub GetNavigatorManu(ByVal SessToken As String, ByVal AppKey As String)
    
            Dim request As HttpWebRequest = Nothing
            Dim response As HttpWebResponse = Nothing
    
    
            Dim strResponseStatus As String = ""
            Try
                request = WebRequest.Create(New Uri("https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json"))
    
                request.Accept = "application/json"
                request.Method = "GET"
                request.KeepAlive = True
                request.ContentType = "application/json"
                request.AutomaticDecompression = DecompressionMethods.GZip Or DecompressionMethods.Deflate
                request.Headers.Add("Accept-Encoding", "gzip,deflate")
                request.Headers.Add("X-Authentication", SessToken)
                request.Headers.Add("X-Application", AppKey)
    
                '~~> Get the response.
                response = request.GetResponse()
                '~~> Display the status below 
                strResponseStatus = "Status is " & CType(response, HttpWebResponse).StatusCode
    
            Catch ex As Exception
                MsgBox("CreateRequest Error" & vbCrLf & ex.Message)
            End Try
            MsgBox(strResponseStatus)
            '~~~Clean Up
    
        End Sub
    Make sure you call the routine with both the session token and the app key.

    Comment

    • ahn
      Junior Member
      • Jul 2011
      • 12

      #3
      Navigate Application

      Originally posted by betdynamics View Post
      I'm not too familiar with VB, but you could try the following:

      Code:
      Sub GetNavigatorManu(ByVal SessToken As String, ByVal AppKey As String)
      
              Dim request As HttpWebRequest = Nothing
              Dim response As HttpWebResponse = Nothing
      
      
              Dim strResponseStatus As String = ""
              Try
                  request = WebRequest.Create(New Uri("https://api.betfair.com/exchange/betting/rest/v1/en/navigation/menu.json"))
      
                  request.Accept = "application/json"
                  request.Method = "GET"
                  request.KeepAlive = True
                  request.ContentType = "application/json"
                  request.AutomaticDecompression = DecompressionMethods.GZip Or DecompressionMethods.Deflate
                  request.Headers.Add("Accept-Encoding", "gzip,deflate")
                  request.Headers.Add("X-Authentication", SessToken)
                  request.Headers.Add("X-Application", AppKey)
      
                  '~~> Get the response.
                  response = request.GetResponse()
                  '~~> Display the status below 
                  strResponseStatus = "Status is " & CType(response, HttpWebResponse).StatusCode
      
              Catch ex As Exception
                  MsgBox("CreateRequest Error" & vbCrLf & ex.Message)
              End Try
              MsgBox(strResponseStatus)
              '~~~Clean Up
      
          End Sub
      Make sure you call the routine with both the session token and the app key.
      Unfortunately, the same error appears!

      Comment

      • ahn
        Junior Member
        • Jul 2011
        • 12

        #4
        I have found my bug. Actually it was the AppKey!

        Comment

        Working...
        X