url encode support

Q&A's, tips, howto's

url encode support

Postby csfreebird » Fri Apr 10, 2015 4:26 am

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?
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing

Re: url encode support

Postby ralph.ronnquist » Fri Apr 10, 2015 5:25 am

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.
ralph.ronnquist
 
Posts: 215
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: url encode support

Postby Lutz » Fri Apr 10, 2015 5:37 am

Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 3 guests

cron