Skip to main content

I am trying to post a JSON body to a RESTful API. Im having issue with post, the request isnt happening. I just recently discoved RMNet and have HttpGet requests working with my own parsing. Everything i can find is on xml and SOAP usage with post. 

IDENTIFICATION DIVISION.
PROGRAM-ID. EXECNODE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WSOK PIC X.
01 DESTINATION-URL PIC X(200)
VALUE "localhost:5001/.../cobol".
01 content-type PIC X(45)
value "application/json; charset=utf-8".
01 ws-request-len PIC 9(5).
01 request-pointer USAGE POINTER.
01 response-pointer USAGE POINTER.
01 http-return-code PIC 9(03).
01 http-return-code-text PIC X(40).
01 ws-status-code PIC S9(03) VALUE 0.
01 ws-error-pointer USAGE POINTER.
01 ws-error-len PIC 9(04).
LINKAGE SECTION.
01 lk-error-message PIC X(1000).
01 lk-response-payload PIC X(1000000).
01 lk-request-body PIC X(20)
value '{"test":"value"}'.
PROCEDURE DIVISION.
000-BEGIN-PROGRAM SECTION.
100-EXEC-NODE.
CALL "NetInit" GIVING WS-STATUS-CODE.
ACCEPT WSOK.
set address of lk-request-body to request-pointer.
CALL 'HttpPost' USING
destination-url,
content-type,
request-pointer,
response-pointer
GIVING http-return-code.
call "HttpGetReturnCode" using http-return-code
giving ws-status-code.
evaluate ws-status-code
when 200
move "OK" to http-return-code-text.
display http-return-code-text.
ACCEPT WSOK.
EXIT PROGRAM.

I am trying to post a JSON body to a RESTful API. Im having issue with post, the request isnt happening. I just recently discoved RMNet and have HttpGet requests working with my own parsing. Everything i can find is on xml and SOAP usage with post. 

IDENTIFICATION DIVISION.
PROGRAM-ID. EXECNODE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WSOK PIC X.
01 DESTINATION-URL PIC X(200)
VALUE "localhost:5001/.../cobol".
01 content-type PIC X(45)
value "application/json; charset=utf-8".
01 ws-request-len PIC 9(5).
01 request-pointer USAGE POINTER.
01 response-pointer USAGE POINTER.
01 http-return-code PIC 9(03).
01 http-return-code-text PIC X(40).
01 ws-status-code PIC S9(03) VALUE 0.
01 ws-error-pointer USAGE POINTER.
01 ws-error-len PIC 9(04).
LINKAGE SECTION.
01 lk-error-message PIC X(1000).
01 lk-response-payload PIC X(1000000).
01 lk-request-body PIC X(20)
value '{"test":"value"}'.
PROCEDURE DIVISION.
000-BEGIN-PROGRAM SECTION.
100-EXEC-NODE.
CALL "NetInit" GIVING WS-STATUS-CODE.
ACCEPT WSOK.
set address of lk-request-body to request-pointer.
CALL 'HttpPost' USING
destination-url,
content-type,
request-pointer,
response-pointer
GIVING http-return-code.
call "HttpGetReturnCode" using http-return-code
giving ws-status-code.
evaluate ws-status-code
when 200
move "OK" to http-return-code-text.
display http-return-code-text.
ACCEPT WSOK.
EXIT PROGRAM.

Sorry tried to get the editor to keep the formatting but no success.

I am trying to post a JSON body to a RESTful API. Im having issue with post, the request isnt happening. I just recently discoved RMNet and have HttpGet requests working with my own parsing. Everything i can find is on xml and SOAP usage with post. 

IDENTIFICATION DIVISION.
PROGRAM-ID. EXECNODE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WSOK PIC X.
01 DESTINATION-URL PIC X(200)
VALUE "localhost:5001/.../cobol".
01 content-type PIC X(45)
value "application/json; charset=utf-8".
01 ws-request-len PIC 9(5).
01 request-pointer USAGE POINTER.
01 response-pointer USAGE POINTER.
01 http-return-code PIC 9(03).
01 http-return-code-text PIC X(40).
01 ws-status-code PIC S9(03) VALUE 0.
01 ws-error-pointer USAGE POINTER.
01 ws-error-len PIC 9(04).
LINKAGE SECTION.
01 lk-error-message PIC X(1000).
01 lk-response-payload PIC X(1000000).
01 lk-request-body PIC X(20)
value '{"test":"value"}'.
PROCEDURE DIVISION.
000-BEGIN-PROGRAM SECTION.
100-EXEC-NODE.
CALL "NetInit" GIVING WS-STATUS-CODE.
ACCEPT WSOK.
set address of lk-request-body to request-pointer.
CALL 'HttpPost' USING
destination-url,
content-type,
request-pointer,
response-pointer
GIVING http-return-code.
call "HttpGetReturnCode" using http-return-code
giving ws-status-code.
evaluate ws-status-code
when 200
move "OK" to http-return-code-text.
display http-return-code-text.
ACCEPT WSOK.
EXIT PROGRAM.

A couple problems I see at first glance:

"set address of lk-request-body to request-pointer" is backwards; destination and source are reversed in the SET statement.  It probably should be:

set request-pointer to address of lk-request-body 

Second, you appear to expect the VALUE clause in LINKAGE SECTION to initialize data values.  The VALUE clause is correct data-item syntax in LINKAGE, but is useful only with the INITIALIZE verb. Since this is probably just a prototype hack to get something working, move lk-request-body to WORKING-STORAGE.

I don't have extend installed, so I cannot look at the RMnet examples that are included in the RMnet package.

You also say, " Everything i can find is on xml and SOAP usage with post. "   There is nothing special about JSON, or XML, or whatever.  HttpPost is simply a transport mechanism for the request and response.  RMnet is merely a wrapper for the curl library, so you can often find examples in the documentation for curl itself that give you hints.  JSON or XML is just a blob of data to which the applications give meaning.

Finally, there is no reason to write your own parser.  If you are using XML Extensions for other purposes, you can find an article at http://www.tek-tips.com/viewthread.cfm?qid=1709035 which I wrote in 2013 on how to parse JSON using XSLT (which is used manipulate XML documents).  While this article does not mention XML Extensions because of its venue, the result is an XML document that can be imported easily using XML Extensions.  I have several clients using this solution.  (Hint:  go all the way to the bottom for a clean set of source code.)

I will be watching this thread...


I am trying to post a JSON body to a RESTful API. Im having issue with post, the request isnt happening. I just recently discoved RMNet and have HttpGet requests working with my own parsing. Everything i can find is on xml and SOAP usage with post. 

IDENTIFICATION DIVISION.
PROGRAM-ID. EXECNODE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WSOK PIC X.
01 DESTINATION-URL PIC X(200)
VALUE "localhost:5001/.../cobol".
01 content-type PIC X(45)
value "application/json; charset=utf-8".
01 ws-request-len PIC 9(5).
01 request-pointer USAGE POINTER.
01 response-pointer USAGE POINTER.
01 http-return-code PIC 9(03).
01 http-return-code-text PIC X(40).
01 ws-status-code PIC S9(03) VALUE 0.
01 ws-error-pointer USAGE POINTER.
01 ws-error-len PIC 9(04).
LINKAGE SECTION.
01 lk-error-message PIC X(1000).
01 lk-response-payload PIC X(1000000).
01 lk-request-body PIC X(20)
value '{"test":"value"}'.
PROCEDURE DIVISION.
000-BEGIN-PROGRAM SECTION.
100-EXEC-NODE.
CALL "NetInit" GIVING WS-STATUS-CODE.
ACCEPT WSOK.
set address of lk-request-body to request-pointer.
CALL 'HttpPost' USING
destination-url,
content-type,
request-pointer,
response-pointer
GIVING http-return-code.
call "HttpGetReturnCode" using http-return-code
giving ws-status-code.
evaluate ws-status-code
when 200
move "OK" to http-return-code-text.
display http-return-code-text.
ACCEPT WSOK.
EXIT PROGRAM.

Tom,
Thank you for the quick reply. Yes this is just some testing for viability at the moment, better part of a year at this and i'm still learning every day. At first i was thinking there was something i was missing in the RMnet documentation and all the samples provided with it used XSLT for post methods so i was looking at curl amidst your reply to see how this was implemented to make sure there wasnt something i was missing. I couldnt fathom RMNet being tightly coupled to a specific serialization method, but I always have to dig deeper :) All my APIs i consume use JSON Serialization so i've been parsing myself. I will give that article a read and try it out., thank you for that!

I am trying to post a JSON body to a RESTful API. Im having issue with post, the request isnt happening. I just recently discoved RMNet and have HttpGet requests working with my own parsing. Everything i can find is on xml and SOAP usage with post. 

IDENTIFICATION DIVISION.
PROGRAM-ID. EXECNODE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WSOK PIC X.
01 DESTINATION-URL PIC X(200)
VALUE "localhost:5001/.../cobol".
01 content-type PIC X(45)
value "application/json; charset=utf-8".
01 ws-request-len PIC 9(5).
01 request-pointer USAGE POINTER.
01 response-pointer USAGE POINTER.
01 http-return-code PIC 9(03).
01 http-return-code-text PIC X(40).
01 ws-status-code PIC S9(03) VALUE 0.
01 ws-error-pointer USAGE POINTER.
01 ws-error-len PIC 9(04).
LINKAGE SECTION.
01 lk-error-message PIC X(1000).
01 lk-response-payload PIC X(1000000).
01 lk-request-body PIC X(20)
value '{"test":"value"}'.
PROCEDURE DIVISION.
000-BEGIN-PROGRAM SECTION.
100-EXEC-NODE.
CALL "NetInit" GIVING WS-STATUS-CODE.
ACCEPT WSOK.
set address of lk-request-body to request-pointer.
CALL 'HttpPost' USING
destination-url,
content-type,
request-pointer,
response-pointer
GIVING http-return-code.
call "HttpGetReturnCode" using http-return-code
giving ws-status-code.
evaluate ws-status-code
when 200
move "OK" to http-return-code-text.
display http-return-code-text.
ACCEPT WSOK.
EXIT PROGRAM.

Tom,
That fixed it, Thank you very much!