Rest Service Post Json containing Base64 encoded data

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
bob.elko@hajoca.com
Posts: 2
Joined: Wed Apr 19, 2023 7:04 pm

Rest Service Post Json containing Base64 encoded data

Post 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?
jonboy49
Posts: 205
Joined: Wed Jul 28, 2021 8:18 pm

Re: Rest Service Post Json containing Base64 encoded data

Post 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.
bob.elko@hajoca.com
Posts: 2
Joined: Wed Apr 19, 2023 7:04 pm

Re: Rest Service Post Json containing Base64 encoded data

Post 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.
jonboy49
Posts: 205
Joined: Wed Jul 28, 2021 8:18 pm

Re: Rest Service Post Json containing Base64 encoded data

Post by jonboy49 »

Yup - that would have screwed it up even better!

Glad you sorted it out.
Post Reply