4

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?

ketan
  • 17,717
  • 41
  • 50
  • 83
Peldi Guilizzoni
  • 389
  • 4
  • 11

3 Answers3

5

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 Guilizzoni
  • 389
  • 4
  • 11
4

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
  • 26,815
  • 4
  • 46
  • 71
0

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
  • 12,814
  • 4
  • 34
  • 48