Page 1 of 1

Rest Service Post Json containing Base64 encoded data

Posted: Wed Apr 19, 2023 7:24 pm
by bob.elko@hajoca.com
I'm using HTTPAPI to post to a rest service that requires one element to be base64 encoded and I'm running into a tranlation problem.

My json needs to be
{
"file":"base64encodedfilecontents",
"replace":"true",
"domain":"Default"
}

in my rpg program I'm reading a text file into a string then encode it using the base64_encode function. Then I put it together as shown above and post it with http_url_post. I get a 400 response - Unable to parse xml file: Content is not allowed in prolog.

how can I properly encode my request?

Re: Rest Service Post Json containing Base64 encoded data

Posted: Wed Apr 19, 2023 7:36 pm
by jonboy49
Have you told HTTPAPI to use the correct CCSID for the network? e.g.

Code: Select all

http_setOption ( 'network-ccsid' : '1208' );
If that is not the issue we'll need to see more of your code.

Re: Rest Service Post Json containing Base64 encoded data

Posted: Wed Apr 19, 2023 8:02 pm
by bob.elko@hajoca.com
I figured it out. I opened the file with the O_Textdata flag so I encoded the ebcdic data. I removed it and it's fine now.

Re: Rest Service Post Json containing Base64 encoded data

Posted: Wed Apr 19, 2023 8:19 pm
by jonboy49
Yup - that would have screwed it up even better!

Glad you sorted it out.