ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

url encode special characters

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • url encode special characters

    Hello code400 friends,


    I am working on a program to consume a web service by passing query params.

    To handle special characters in the URL, i.e. & (amp), space, etc, I am doing the scan and replace each special character and encode. Ex: Replace "&" with %26, space with %20, " with %22 etc.

    Is this the correct approach or is there a better way to handle all special characters rather than checking for each special character in a string?

    Ex: To search for customer Customer "A & R Resources, the URL should be /customer/get?CustomerName=A%26R%20Resources



    Thank you.

  • #2
    Well the "better way" would be to use an existing library that already offers the routines needed. Scott Klement's HTTPAPI is the one that most people use. http://scottklement.com/httpapi/

    Why waste hours reinventing the wheel? Using his stuff I can get a simple consumer program written in less than an hour including all the DS etc. needed to use it with DATA-GEN/DATYA-INTO or the raw YAJL routines.

    Another option is to use Giovanni's URL routines from the Easy400.net web site.

    Comment


    • #3
      I (predictably) sgree with the HTTPAPI recommendation.

      But it might be worth mentioning that IBM ships a URLENCODE function with SQL https://www.ibm.com/docs/en/i/7.4?to...calar-function

      Comment

      Working...
      X