How to encode URI?

Posted by goo on 22-Feb-2018 12:11


I am trying to send a URI with query param, but I am not getting a correct format. 

If I try to send"test tast tust" as a message to SMS, it breaks.

If I use Uri(" tast tust",false) I am geting it converted, but I recevie it like"test+tast+tust"

If I try to send "test & tust", the & will not be converted, and it breaks the link when seeing in the phone.

I have got it to work, by converting space to _ and & to X like "test_X_tust", and reconverting it when it comes to the page, but my heart bleeds doing something like that :-)

Is there a spesific way of encoding for sms ?

All Replies

Posted by Jens Dahlin on 23-Feb-2018 03:51

I don't know about the SMS part but there are some encodings you need to do for urls:

First of all: you cannot use spaces in a URL.

test tast tust (without any quotes) should be sent as test+tast+tust (spaces replaced with +).

For example: server?value=test+tast+tust

“test tast tust” with quotes should be encoded to

%22test+tast+tust%22 (“ replaced with %22 and spaces with +)

For example: server?value=%22test+tast+tust%22

Posted by Peter Judge on 26-Feb-2018 03:30

If it follows the rules  per RFC 3986 then you should use the Encode() method on the URI object. Basically this-  [View:]

so something like

def var myURI as OpenEdge.Net.URI.
def var encodedUri as character.

myURI = new URI(' and y').

encodedURI = myURI:Encode().

Posted by goo on 26-Feb-2018 04:06

Thanks Peter, I will try that.
//Geir Otto

This thread is closed