[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: http_persist_req( 'GET') method



Hi Drew,

In my opinion, you are doing this the "hard way" by using http_persist_req(). What is your reason for using that instead of http_get() or http_url_get_raw()?

But, no matter -- if you prefer to use http_persist_req(), it'll work. The data is being passed back to your program via the 'mysaveproc' that you've coded. Each time some data arrives over the network, that procedure is called with the data. so it can be called many times, each time feeding whatever data has just arrived.

If your goal is to put that data into a string variable, then just code that in your procedure. For example:

        ResultString = '';   // this is a "VARYING" string.
        ... call http_persist_xxx routines here....

   p mysaveproc      b
   d                 pi            10i
   d fd                            10i 0 value
   d data                       65535a   options(*varsize)
   d length                        10i 0 value
    /free
      if length > 0;
        resultString = resultString + %subst(data:1:length);
      endif;
      return length;
   p mysaveproc      e

when http_persist_req() returns control back to it's caller, "resultString" will be filled in with all of the data that arrived over the network. It will be in the same character encoding that was sent from the server (probably UTF-8) but you can call one of the http_xlate() routines to convert it to EBCDIC if you desire. Or, if on V7R2, you could use RPG's built-in UTF-8 support for that stuff by adding the appropriate CCSID keywords, etc.

Hope that helps.

On 2/10/2016 10:34 PM, Drew White wrote:
    [cid:image001.gif@01D16452.87082990]

    All,

      Can someone provide a working example (rpg) that show how to retrieve
    data returned by using the http_persist_req( 'GET') method?  I have
    code that works but now sure how to parse the json it returns.  I can
    tell by the logs that it works.  I just can't determine how to get the
    json data returned back into a variable so I can evaluate it.


    Any help appreciated.



    Example of call:


       Pointer = http_persist_open( URL );

       if (pointer = *null);

           RETURN;

       endif;


      monitor;

             http_persist_req( 'GET'

                               : pointer

                               : url

                               : 0

                               : *null

                               : *null

                               : 0

                               : peFD

                               : %paddr(mysaveproc));

      on-error;

        rc=rc;

      endmon;


    http_persist_close( Pointer );


    p mysaveproc      b

    d                 pi            10i

    d fd                            10i 0 value

    d data                            *   value

    d length                        10i 0 value


         return length;

    p mysaveproc      e





    Log

    SetError() #0:

    [

      {

        "id": "5397a88f-5071-45c4-80cb-a5a7018155e7",

        "keyColumn": "0000041",

        "value":
    "\"[\\\"41\\\",\\\"0\\\",\\\"0\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"0\\\"
    ,\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"TARRANTDREW\\\"]\"",

        "url": null

      }

    ]

    http_close(): entered

    HTTPAPI Ver 1.29 released 2015-02-23

    NTLM Ver 1.4.0 released 2014-12-22

    OS/400 Ver V7R1M0


    http_setauth(): entered




-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------