("Accept-Encoding", "gzip, deflate");

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Guest

    #1

    ("Accept-Encoding", "gzip, deflate");

    Ok so I am reading To optimise performance and ensure that your application is interacting with the Betfair API as efficiently as possible, we strongly recommend the following as best practice and enable HTTP compression which I assume is adding

    request.Headers.Add("Accept-Encoding", "gzip, deflate")


    OK but where? I am using the CSharp example (ported to VB NET) and I have JsonRpcClient.vb which contains all the code to talk to API. Should I add this code into my constructor as follows

    Public Sub New(ByVal endPoint As String, ByVal appKey As String, ByVal sessionToken As String)
    'THIS CONSTRUCTOR ADDS THE URL AND THEN ADDS THE APPLICATION KEY AND SESSION TOKEN INTO OUR WEBREQUEST
    Me.EndPoint = endPoint '& "/json-rpc/v1"
    CustomHeaders = New NameValueCollection()
    If appKey IsNot Nothing Then
    CustomHeaders(APPKEY_HEADER) = appKey
    'ADDED 13 MARCH 2017 AND HOPEFULLY SHOULD MAKE THE SYSTEM QUICKER?
    'CustomHeaders("Accept-Encoding") = "gzip, deflate"
    End If
    If sessionToken IsNot Nothing Then
    CustomHeaders(SESSION_TOKEN_HEADER) = sessionToken
    End If
    Me.Timeout = 10000
    End Sub
    OR in CreateWebRequest function
    '################################################# ################################################## ###############
    '### CREATE WEB REQUEST ###
    '################################################# ################################################## ###############
    Protected Function CreateWebRequest(ByVal uri As Uri) As WebRequest
    Dim request As WebRequest = WebRequest.Create(New Uri(EndPoint))
    request.Method = "POST"
    request.ContentType = "application/json-rpc"
    request.Headers.Add(HttpRequestHeader.AcceptCharse t, "ISO-8859-1,utf-8")
    ServicePointManager.Expect100Continue = False

    'ADDED 13 MARCH 2017 AND HOPEFULLY SHOULD MAKE THE SYSTEM QUICKER?
    'request.Headers.Add("Accept-Encoding", "gzip, deflate")

    request.Headers.Add(CustomHeaders)
    Return request
    End Function

    I added both and tested but I get response errors so something wrong.
  • BigSprout
    Junior Member
    • Feb 2011
    • 60

    #2
    Hi Troy,
    I initially tried using "request.Headers.Add("Accept-Encoding", "gzip, deflate")" but couldn't get it to work either.


    I got mine to work by using this coding in the CreateWebRequest instead of of the above (VB):

    request.AutomaticDecompression = DecompressionMethods.GZip
    request.AutomaticDecompression = DecompressionMethods.Deflate


    hope this helps, still trying to get "Streaming" to work with VB

    Comment

    • jabe
      Senior Member
      • Dec 2014
      • 705

      #3
      It took me ages to get it working, but this (VB.NET) seems to do the trick:

      request.Headers.Add("Content-Encoding: gzip")

      Comment

      • Guest

        #4
        Thanks mate

        Comment

        • thehun10.
          Junior Member
          • Oct 2009
          • 5

          #5
          Originally posted by BigSprout View Post
          Hi Troy,
          I initially tried using "request.Headers.Add("Accept-Encoding", "gzip, deflate")" but couldn't get it to work either.


          I got mine to work by using this coding in the CreateWebRequest instead of of the above (VB):

          request.AutomaticDecompression = DecompressionMethods.GZip
          request.AutomaticDecompression = DecompressionMethods.Deflate


          hope this helps, still trying to get "Streaming" to work with VB
          This should be
          request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

          Otherwise the second line "DecompressionMethods.Deflate" will overwrite the first one.

          I have streaming working with vb.net if you have any questions.

          Comment

          • Lopiner
            Junior Member
            • Feb 2009
            • 117

            #6
            Originally posted by thehun10. View Post
            This should be
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

            Otherwise the second line "DecompressionMethods.Deflate" will overwrite the first one.

            I have streaming working with vb.net if you have any questions.
            You have streaming in VB.net THEHUN10?
            I tried to convert the whole c# project but i'm still struggling.
            fooledbyabet.com

            Comment

            • thehun10.
              Junior Member
              • Oct 2009
              • 5

              #7
              Originally posted by Lopiner View Post
              You have streaming in VB.net THEHUN10?
              I tried to convert the whole c# project but i'm still struggling.

              Hi,

              I didn’t convert the c# examples to vb.net, I added the c# code to a vb.net project and called them from within a vb.net.
              I create a c# form called ePathForm which calls the “Betfair.ESASwagger” example code.
              So from my vb.net code I call my c# form (ePathForm) and the c# form calls the Betfair c# code.


              1. Created a c# form called ePathForm, this c# form calls the c# examples “Betfair.ESASwagger” ect…

              Code from the my c# (ePathForm): -
              using Aping_cs.TO;
              using Aping_cs.Json;
              using System.Threading.Tasks;

              using Betfair.ESAClient;
              using Betfair.ESAClient.Auth;
              using Betfair.ESAClient.Cache;
              using Betfair.ESASwagger.Model;


              namespace Aping_cs
              {

              public partial class ePathForm : Form
              {
              Public m_oePathForm As ePathForm = New ePathForm

              .
              .
              .

              public Boolean LoginJson(string strAppKey,
              string strSessionToken,
              ref string strErrorMsg)
              {
              try
              {
              client = new JsonRpcClient(Url, strAppKey, strSessionToken);
              var marketFilter = new MarketFilter();
              var eventTypes = client.listEventTypes(marketFilter);
              return true;

              }
              catch (APINGException apiExcepion)
              {
              strErrorMsg="Got an exception from Api-NG: " + apiExcepion.ErrorCode;
              return false;
              }
              catch (System.Exception e)
              {
              strErrorMsg="Unknown exception from application: " + e.Message;
              return false;
              }
              }




              2. The vb.net code is like this

              Public m_oePathForm As ePathForm = New ePathForm

              Public Function Login(ByRef strErrorMasg As String) As Boolean
              Dim strErrorMsg As String
              If m_oePathForm.LoginJson(strErrorMsg) Then
              Return True
              Else
              Return False
              End If
              End Function

              Comment

              Working...
              X