Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Mgarner Absent Member.
Absent Member.
3232 views

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.

Tags (2)
0 Likes
8 Replies
Knowledge Partner
Knowledge Partner

RE: RMNet/HttpPost HttpGet

Please post your code.


Tom Morrison
Consultant

0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: RMNet/HttpPost HttpGet

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.

0 Likes
Mgarner Absent Member.
Absent Member.

RE: RMNet/HttpPost HttpGet

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.

0 Likes
dalekreitzer
Visitor.

RE: RMNet/HttpPost HttpGet

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"

            USING

              W-DESTINATION-URL,  W-CONTENT-TYPE

              W-REQUEST-POINTER,  W-REQUEST-LENGTH

              W-RESPONSE-POINTER, W-RESPONSE-LENGTH

              W-EXTRA-HEADERS

          IF W-RESPONSE-LENGTH > 0

              SET ADDRESS OF L-RESPONSE-DATA TO W-RESPONSE-POINTER

              MOVE L-RESPONSE-DATA(1:W-RESPONSE-LENGTH)

                TO W-RESPONSE-DATA

          END-IF

Dale

0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: RMNet/HttpPost HttpGet

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 🙂

0 Likes
Mgarner Absent Member.
Absent Member.

RE: RMNet/HttpPost HttpGet

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

STRING GOGL-URL DELIMITED BY "   "

                 GOGL-ORIGIN DELIMITED BY "   "

                 "&" DELIMITED BY SIZE

                 GOGL-DESTINATION DELIMITED BY "   "

                 "&" DELIMITED BY SIZE

                 GOGL-DISTANCE-KEY DELIMITED BY "   "

                 INTO GOGL-API

END-STRING.

make the call

CALL "HttpGet" USING

                   GOGL-API

                   GOGLR-POINTER

                   10000

                   GIVING STATUS-CODE.

SET ADDRESS OF GOGL-RESPONSE TO GOGLR-POINTER

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

Thanks

0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: RMNet/HttpPost HttpGet

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:

DISPLAY GOGL-RESPONSE(1:RESPONSE-LENGTH)

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

0 Likes
Mgarner Absent Member.
Absent Member.

RE: RMNet/HttpPost HttpGet

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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.