Page 1 of 1

url encode support

PostPosted: Fri Apr 10, 2015 4:26 am
by csfreebird
I want to use get-url to call one REST API, but the URL path of this REST API contains some Chiness words, like this:


when using browser, this url will be encoded by browser automatically:


I didn't find url encode/decode functions in newlisp manual, does anybody implement this before?

Re: url encode support

PostPosted: Fri Apr 10, 2015 5:25 am
by ralph.ronnquist
I suppose this is one of those skin-less cats, but these are what I'm currently using:

Code: Select all
(define (urlencode txt)
  (join (map (fn (c) (format "%02X" (char c))) (explode txt))))


Code: Select all
(define (urldecode txt)
  (replace "%(..)" (replace "+" (copy txt) " ") (char (int $1 32 16)) 0))


I have a memory of having searched some earlier discussion about this, and maybe these are from there. In any case, they work for me, for CGI scripts dealing with forms and form data.

Re: url encode support

PostPosted: Fri Apr 10, 2015 5:37 am
by Lutz