URL encode or REPLACE space with %20

I’m using CURL(url)
but the url does not URL-encode, i.e. doesn’t changes the spaces to %20 etc. As a result i’m getting somewhat unpredictable results. especially since the caller ID (all) is a parameter.

I’m trying the REPLACE(x,y) but the x can be n length while y can only be 1 (or it only uses the first char).

Done anyone know how to either force CURL to encode the URL or to manually encode the URL.

(Asterisk 1.8 )

If applicable You may do the uri-encoding externally by perl:

exten=> s,1,Set(uri=www.example.com?num=gfd avb <123>); exten=> s,n,Set(euri=${SHELL(perl -MURI::Escape -e 'print uri_escape("${uri}");' "$2")}); exten=> s,n,Set(result=${CURL(${euri})})

If You don’t have perl on Your box it’s possible to do the encoding within a bash script You afterwards use inside the SHELL-function

Thanks, but what i found was that there are two characters for space in a URL, and since the space is the main culprit for my issues… replacing the space with a + works the same as %20, and since + is one char long, the REPLACE(x,y) works fine.

this actually works fine now… all the < and > stuff seems to be handled fine by the server

Asterisk has a ${URIENCODE()} function.

(Note that bare space is deliberately not valid in a URI, so that there are no ambiguities when transcribing printed text.)

1 Like