I was recently asked how certain strings could be URL encoded, to be used in a call to the HTTP adapter, to mimic a command in CURL:
curl --location --request POST --insecure --noproxy "*" '<URL>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=<ClientID>' \
--data-urlencode 'client_secret=<secret>'
A long while back, I developed a simple UrlEncoding map, which used the SUBSTITUTE() function to replace certain strings. Today I realised that this example, while workable for a majority of cases, could be confused by characters I had not imagined in my design.
I therefore created a second version of the map, which encodes every character, using he STREAMTOHEXTEXT() function. Possibly overkill, but for ASCII data, bulletproof.
A further enhancement I could consider, is allowing for other character sets.
The resulting strings would make up a simple rule such as:
=GET("HTTP","-URL
http://example.com/post-form-data.cgi?"+RUN("UrlEncoding2.mmc",ECHOIN(1,CPACKAGE(GrantPackage,"NATIVE"))+" -OE1")+"&"+RUN("UrlEncoding2.mmc",ECHOIN(1,CPACKAGE(ClientId,"NATIVE"))+" -OE1")+"&"+RUN("UrlEncoding2.mmc",ECHOIN(1,CPACKAGE(ClientSecret,"NATIVE"))+" -OE1")+" -METHOD post -HEADER+ -TV",HeaderStructure)
The first of the three RUN() functions above, returns %67%72%61%6E%74%5F%74%79%70%65%3D%63%6C%69%65%6E%74%5F%63%72%65%64%65%6E%74%69%61%6C%73 which is is 'grant_type=client_credentials' UrlEncoded.
I welcome feedback.
------------------------------
Paul Brett
IBM Sterling Transformation Extender (ITX) Client Support
------------------------------
#B2BIntegration#SupplyChain