RMNet/HttpPost HttpGet

I am trying to use HttpGet(extend version 9.2) on the google directions api. I have the pointer and a field in the linkage area for the response. The problem is when i use https in the url I get a memory access violation on the field in the linkage area. If use http google tells me i need to use https. I am not sure why i am getting to MAV.

Thanks in advance for any help.

  • The call to HttpGet should return a response-pointer. You can dereference it by using it in a SET ADDRESS OF statement like this:

    set address of lk-response-payload to response-pointer

    ...where lk-response-payload is defined in the Linkage Section (use something suitably large like PIC X(100000)*. response-pointer should be defined in Working-Storage as USAGE POINTER.

    *(actually, I'm not sure the size matters unless you're going to refer to it using reference modification)..

    I think I've got a working demo of this that I'll try to dig up and send you.

  • I was using pic x(3000) for the linkage field. I'll increase it to see if that works. thanks for looking for the demo.

  • I was using pic x(3000) for the linkage field. I'll increase it to see if that works. thanks for looking for the demo.

  • I was using pic x(3000) for the linkage field. I'll increase it to see if that works. thanks for looking for the demo.

  • One additional suggestion.  You should define an additional field in working storage, with a large data size, for the buffer.  You can't reference the entire buffer from linkage, as you will be accessing data outside the size of the field.    You can only access the length of the address returned.   By moving it to your own defined space, you can be assured of not accessing memory you don't own.

    In the code example below, L-RESPONSE-DATA is in linkage, and W-RESPONSE-DATA is defined in working storage.  

              CALL "HttpPost"






              IF W-RESPONSE-LENGTH > 0



                    TO W-RESPONSE-DATA


  • Ok, I found my demo/test program, and even modified it to use the Google Maps API. It makes a call to the Google Maps "Directions" service, and gets back a JSON-formatted response. You'll need to get your own SSL-CA file (cacert.pem, which you can get from http://curl.haxx.se/docs/caextract.html). You'll also need to get your own API key from Google APIs (https://console.developers.google.com/apis/credentials) and edit the program with the correct key.

    Read the first few lines of the program for instructions on compiling and running. I assume you're trying this on AIX... I haven't tried it there but it works on Linux and Windows. I'm also attaching a Makefile which might work for compiling and running in your environment, once you make a few necessary edits.

    When you run it, it'll retrieve the response, display the http headers and the first few lines of the content/payload, and give you the option to save the payload to a file. The save-to-file option isn't very well optimized - it just writes out the payload one-byte-at-a-time, but I wasn't going for efficiency with this demo :)

  • I am setting the Origin, Destination and Key in working storage.  Then stringing that in to a field called GOGL-API


                     GOGL-ORIGIN DELIMITED BY "   "

                     "&" DELIMITED BY SIZE

                     GOGL-DESTINATION DELIMITED BY "   "

                     "&" DELIMITED BY SIZE

                     GOGL-DISTANCE-KEY DELIMITED BY "   "

                     INTO GOGL-API


    make the call

    CALL "HttpGet" USING




                       GIVING STATUS-CODE.


    when i try to display GOGL-RESPONSE i get the MAV.


  • One thing I'd suggest is using an actual numeric data-item for your 3rd parameter. It's meant to be a receiving field, that will get populated with the length of the response returned by the HttpGet call. Then restrict your display of GOGL-RESPONSE to the number of bytes it has allocated:


    Or, you can copy the data to a Working-Storage field as Dale K suggested a few posts up.

  • Ah, that was it I was using a numeric literal instead of a data item... thanks for the help