RocketSoftware / multivalue-lab

Demo code from Rocket's MV Servers Lab for UniVerse/UniData/D3 and associated clients, APIs & tools
MIT License
72 stars 83 forks source link

Encoding "post_data" value of submitRequest function #68

Closed wags closed 8 years ago

wags commented 9 years ago

Hi, I'm working with the submitRequest function on a UniVerse server (running v11.2.3). I'm posting data to a web service and am manually crafting the specifically-formatted XML request data it requires and including that as the post_data parameter of the function. When I do this, it looks like I'm going to have to manually look for any characters that aren't HTML-safe, like the ampersand (&) symbol and change it to &.

Is there a built-in/automated way to do it, or has anyone already written a nice routine to handle things like that?

Thanks!

wags commented 8 years ago

I have found various solutions to do this. One is to use the ENCODE function:

ENCODE(algorithm, action, data, dataLoc, result, resultLoc)

Simply pass "URLENCODE" as the value for algorithm above.

Another way is to use UDO objects. Upon writing the object to JSON or XML, the proper escaping is done automatically. This is especially helpful when trying to create JSON that contains quote marks in the data. It all comes out in properly-escaped JSON, like \".