Whats the GWT equivalent of urlencode?

5,025 views
Skip to first unread message

darkflame

unread,
Mar 27, 2009, 12:45:13 PM3/27/09
to Google Web Toolkit
I got data being recieved in my GWT program from a PHP function which
is using urlencode(string) to encode the data.

What do I need to do on the GWT to correctly decode this data?

I tried just " URL.decode(string) " but this clearly isnt decodeing
it correctly (slash's, for example, are still "+%2F")

What other decodeing functinos are there?
Or should I change the php end to encode it differently?

mel

unread,
Mar 27, 2009, 3:11:47 PM3/27/09
to Google Web Toolkit

Its URL.encode(String) from the com.google.gwt.http.client package.

Thomas Wrobel

unread,
Mar 27, 2009, 3:14:40 PM3/27/09
to Google-We...@googlegroups.com
That was the one I tried already, it dosnt decode backslash's correctly.
(that is "+%2F" isnt decoded)
Thanks anyway.

~~~~~~
Reviews of anything, by anyone;
www.rateoholic.co.uk
Please try out my new site and give feedback :)



2009/3/27 mel <mped...@stuart.iit.edu>:

Ian Bambury

unread,
Mar 27, 2009, 3:29:43 PM3/27/09
to Google-We...@googlegroups.com
2F is a forward slash which doesn't get encoded therefore doesn't need decoding

5C is the backslash which works OK for me

Ian

http://examples.roughian.com


2009/3/27 Thomas Wrobel <dark...@gmail.com>

Thomas Wrobel

unread,
Mar 27, 2009, 3:59:03 PM3/27/09
to Google-We...@googlegroups.com
Well, something is being encoded as 2F by php, and not being decoded.
(along with a lot of other random changes) I'm most certainly not
getting the same strings in/out with

urlencode(String) on the php side and URL.decode(string) on the java side.

My tests where just with random generated strings, I expected just to
confirm it was the same, but it dosnt seem to be.

I just want a guarantied way to communicate between php and gwt with
preservation of *all* characters frankly. (as I may want to send
encrypted strings, I dont want to worry about what characters I can
use/not use in the encyption).

~~~~~~
Reviews of anything, by anyone;
www.rateoholic.co.uk
Please try out my new site and give feedback :)



2009/3/27 Ian Bambury <ianba...@gmail.com>:

Ian Bambury

unread,
Mar 27, 2009, 5:13:12 PM3/27/09
to Google-We...@googlegroups.com
Sorry, I didn't read your first post, just the one I replied to.

This is not a uniquely GWT problem, it is a PHP/JavaScript problem (as GWT just calls a JS function)

PHP encodes differently to JS.

The only problem I am aware of (maybe other people can chip in here) is PHP encoding the backslash. '()*~! all seem OK, but I haven't had too much involvement with this.

If no-one comes up with a better solution then a simple replace might be the best answer.

Ian Bambury

unread,
Mar 27, 2009, 5:13:57 PM3/27/09
to Google-We...@googlegroups.com
Sorry (doh!) forward slash, not backslash.

Thomas Broyer

unread,
Mar 28, 2009, 10:43:26 AM3/28/09
to Google Web Toolkit

On 27 mar, 17:45, darkflame <darkfl...@gmail.com> wrote:
> I got data being recieved in my GWT program from a PHP function which
> is using urlencode(string) to encode the data.
>
> What do I need to do on the GWT to correctly decode this data?
>
> I tried just  " URL.decode(string) " but this clearly isnt decodeing
> it correctly (slash's, for example, are still "+%2F")
>
> What other decodeing functinos are there?

URL.decodeComponent(String) is the thing to use to decode PHP's
urlencode(string) result.

URL.encode()/URL.decode() is designed to work with full URLs (i.e.
turn "http://example.net/foo bar/bâz?q=uüx" into "http://example.net/
foo%20bar/b%C3%A2z?q=u%C3%BCx")

See:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/decodeURI
(the thing behind URL.decode())
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/decodeURIComponent
(the thing behind URL.decodeComponent())

And if you plan using URL.encodeComponent, see
http://code.google.com/p/google-web-toolkit/issues/detail?id=3374

Reply all
Reply to author
Forward
0 new messages