views:

1600

answers:

3

I load some XML from a servlet from my Flex application like this:

_loader = new URLLoader(); _loader.load(new URLRequest(_servletURL+"?do=load&id="+_id));

As you can imagine _servletURL is something like http://foo.bar/path/to/servlet

In some cases, this URL contains accented characters (long story). I pass the unescaped string to URLRequest, but it seems that flash escapes it and calls the escaped URL, which is invalid. Ideas?

+4  A: 

I'm not sure if this will be any different, but this is a cleaner way of achieving the same URLRequest:

var request:URLRequest = new URLRequest(_servletURL)
request.method = URLRequestMethod.GET;
var reqData:Object = new Object();

reqData.do = "load";
reqData.id = _id;
request.data = reqData;

_loader = new URLLoader(request);
grapefrukt
thanks, but while prettier, it made no difference
Peldi
A: 

From the livedocs: http://livedocs.adobe.com/flex/3/langref/flash/net/URLRequest.html

Creates a URLRequest object. If System.useCodePage is true, the request is encoded using the system code page, rather than Unicode. If System.useCodePage is false, the request is encoded using Unicode, rather than the system code page.

This page has more information: http://livedocs.adobe.com/flex/3/html/help.html?content=18_Client_System_Environment_3.html

but basically you just need to add this to a function that will be run before the URLRequest (I would probably put it in a creationComplete event)

System.useCodePage = false;

Ryan Guill
Thanks, but from that same page it says useCodePage is false by default. Anyways, I'll experiment
Peldi
useCodePage is a bit of a hack, since it uses the system codepage it might work on a machine to english but fail on all others.
grapefrukt
+3  A: 

My friend Luis figured it out:

You should use encodeURI does the UTF8URL encoding http://livedocs.adobe.com/flex/3/langref/package.html#encodeURI()

but not unescape because it unescapes to ASCII see http://livedocs.adobe.com/flex/3/langref/package.html#unescape()

I think that is where we are getting a %E9 in the URL instead of the expected %C3%A9.

http://www.w3schools.com/TAGS/ref_urlencode.asp

Peldi