When using http_req, the "File to receive" function works fine, but how can I use the "String to receive" option to receive a JSON body like this?
{
"encryptString": "138",
"hexString": "5BF28981860"
}
my code
Code: Select all
D rc s 10I 0
D msg s 25A
D url1 s 300A
D url2 s 300A
D parm1 s 100A
D parm2 s 8A
D responseBody s a len(16000000) varying
D debugLog s 32A varying inz
D urlFull s 32767a varying
D res s 50a
/free
url1 = 'http://192.168.0.1:9090/test/api';
parm1 = 'encryptString=138';
urlFull = %trim(url1) + %trim(parm1);
debugLog = '/home/qsnp252/' ;
http_debug(*ON: debugLog + 'testrest.log');
http_setOption( 'content-type'
: 'application/json' );
rc = http_req( 'GET'
: urlFull
: '/home/qsnp252/test.json' // File to receive
: responseBody // String to receive
: *omit // File to send
: *omit // String to send
);
if rc <> 1;
msg = http_error();
dsply ('error:' + msg);
else;
res = %subst(responseBody : 1 : 50);
dsply res;
dsply 'OK';
endif;
https_cleanup();
*inlr = *on;
return;
/end-free