errors trying to make basic calls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OzPunter
    Junior Member
    • Apr 2009
    • 161

    #1

    errors trying to make basic calls

    In an attempt to circumvent a whole pile of code that could be contributing to the Memory Leaks problem, I have started from scratch with the barest minimum code.

    Regardless of what I try I end up with either “Invalid Requests”, “404 errors” or “Invalid media type”

    This is what I’m POSTing;

    httpClient.Post('https://api.betfair.com/exchange/betting/rest/v1.0/listEventTypes/',lParamList);

    where IParamlist is

    lParamList := TStringList.Create;
    lParamList.Add('{"filter" :{}}');

    And the response is “Invalid media type”

    So I’m not getting anywhere, and time is running out…

    If I can't find a way around these memory leaks, the whole thing is sunk.
  • betdynamics
    Junior Member
    • Sep 2010
    • 534

    #2
    Did you set the X-Application and X-Authentication headers before making the calls?

    Comment

    • OzPunter
      Junior Member
      • Apr 2009
      • 161

      #3
      the code

      procedure TForm1.Button2Click(Sender: TObject);
      var
      httpClient : TIdHttp ;
      sslIOHandler : TIdSSLIOHandlerSocketOpenSSL ;
      Response : string ;
      error : string;

      lParamList: TStringList;
      begin
      lParamList := TStringList.Create;
      lParamList.Add('{"filter" :{}}');
      Error := '' ;
      Response := '' ;
      httpClient := TIdHttp.Create(nil) ;
      httpClient.Request.Accept := 'application/json' ;
      httpClient.ReadTimeout := 60000 ;
      httpClient.Request.CustomHeaders.Add('X-Authentication:' + SessionToken ) ;
      httpClient.Request.CustomHeaders.Add('X-Application:' + App_Key ) ;
      sslIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil) ;
      httpClient.IOHandler := sslIOHandler ;
      Response := httpClient.Post('https://api.betfair.com/exchange/betting/rest/v1.0/listEventTypes/',lParamList);
      freeandnil(lparamList);
      memo1.text := response;
      end;

      The code fails on the httpClient.Post with "HTTP/1.1415 Unsuported Media Type"

      If I try a ".get" the error is "HTTP/1.1400 Bad Request", so "Gets" are the wrong call..

      I'm logged in and the session and appkey are valid.

      What I'm really trying to get to the bottom of is why I have memory leaks when making JSON calls.. So the aim of this code is to determine where the memory leaks are coming from... My previous project works ok, for about 2 hours and crashes through memory problems.

      Comment

      • betdynamics
        Junior Member
        • Sep 2010
        • 534

        #4
        Don't you need to specify Content-Type and Content-Length in your httpClient?

        Comment

        • OzPunter
          Junior Member
          • Apr 2009
          • 161

          #5
          Thanks for your help BetDynamics, but..





          ContentType = 'application/x-www-form-urlencoded';
          or 'application/json';

          and Contentlength set to any of the length of the URL, or the filter or both (URL+Filter) all produce the Bad Request error.

          Kind Regards
          OzPunter

          Comment

          • OzPunter
            Junior Member
            • Apr 2009
            • 161

            #6
            Originally posted by OzPunter View Post
            Thanks for your help BetDynamics, but..





            ContentType = 'application/x-www-form-urlencoded';
            or 'application/json';

            and Contentlength set to any of the length of the URL, or the filter or both (URL+Filter) all produce the Bad Request error.

            Kind Regards
            OzPunter
            Here's an update.. I made a new procedure to send a "keep Alive" request and got back a Success response, alo tried it when logged out and got back an error message.. So as a test that's encouraging.. all I have to do is figure out why I'm getting Bad Request for the listEventTypes...

            Comment

            • OzPunter
              Junior Member
              • Apr 2009
              • 161

              #7
              I've tried everyting I can think of and every respose is HTTP/1.1400 Bad Request

              I've run out of things to try... Has anyone got code that works?? anyone??

              OzPunter

              Comment

              • OzPunter
                Junior Member
                • Apr 2009
                • 161

                #8
                Think I found it

                it turns out that the httpClient(idHTTP).POST wont accept a Tstringlist as part of it's parameters. It allows it but dosent convert it correctly.

                I needed to do this

                Params := TStringStream.Create();
                Params.WriteString('{"filter":{ }}');

                and call httpClient.Post(URL,Params,res);

                the response (res) also arrives in a TStringStream.. all I have to do now is make sense of the response then I can get back to figuring out where these memory leaks are comming from..

                Kind Regards
                OzPunter

                Comment

                Working...
                X