Skip to main content
Participant
November 13, 2009
Question

URLLoader problem

  • November 13, 2009
  • 3 replies
  • 968 views

Hello, I just started learning flex and I'm working on an issue that has me stumped.  I want to make a request to an application at a url address and I'm expecting an XML response back. 

I was able to get the expected response back using URLRequest, but only if I use navigateToURL.  When I use URLLoader I get a bad response.  Here's my code.

------------

var params:URLVariables = new URLVariables("username=user@email.com");

var request:URLRequest = new URLRequest();

request.url = "http://mydomain.com:8180/functiondir/function"

request.method = URLRequestMethod.POST;

request.data = params;

var urlLoad:URLLoader = new URLLoader();

urlLoad.addEventListener(Event.COMPLETE, ResultHandler);

urlLoad.addEventListener(IOErrorEvent.IO_ERROR, FaultHandler);

urlLoad.addEventListener(HTTPStatusEvent.HTTP_STATUS, HTTPHandler);

urlLoad.addEventListener(SecurityErrorEvent.SECURITY_ERROR, SecHandler);

urlLoad.load(request);

//navigateToURL(request);

---------------

The functions I defined in the event listeners print out diagnostic information.  If I uncomment the line above a browser window will open with the correct XML response in it.  But when I use the urlLoad.load function I get this response in firefox:

----

HTTP Response: '0'

HTTP Done

Error during submit: 'Error #2032'

Error Done

-----

Curiously, if I run the same script in IE8 I get:

----------

HTTP Response: '400'

HTTP Done

Error during submit: 'Error #2032'

Error Done

--------
I under the response means the request is malformed.  But I don't know why it's malformed.  The URL is correct and I'm getting the correct response when I use navigateToURL.  I need to capture the response programmatically.  What could the problem be?
Thanks.

This topic has been closed for replies.

3 replies

Participant
November 18, 2009

I guess this problem is a stumper.

In the crossdomain file, how do I allow all content-types?

November 13, 2009

This is a wild shot in the dark, but if it's saying the request is malformed, does it make a difference if instead of your current encoding, you change your URLVariables code to read:

var params:URLVariables = new URLVariables();

params.username = user@email.com;

I know it shouldn't make a difference, but looking at what you have already it might be worth a shot.

The other issue you might check out (although it doesn't seem like a security issue) is whether there is a problem with the way the code is accessing the server.  Implementing a crossdomain policy file might resolve the situation if it turns out it's not code based.  And just out of curiosity, do you know which of your event handlers is returning the error?

Participant
November 13, 2009

Solitonman,

See above for the crossdomain.xml file I placed.  I tried that format for the params variable... no difference.  The "Http response" is coming from the HTTP_STATUS listener and the "Error during submit" is from  IO_ERROR.

Hmm, hopefully I'm not adding too much information to this but I just ran the same code in chrome and SECURITY_ERROR threw a code (only when using chrome).

-----------

HTTP Response: '0'

HTTP Done

Security: 'Error #2048'

---------------

kglad
Community Expert
Community Expert
November 13, 2009

you probably have a security sandbox issue if you're trying to load data from one sandbox into another.  what domain are you testing from and what domain are you trying to query for the data?

Participant
November 13, 2009

I'm running the client on my computer (using flex builder 3) and accessing the url which is located on my external server.  My server is running tomcat and I placed the following crossdomain.xml file in the ROOT directory:

<?xml version="1.0"?>

<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>

        <allow-access-from domain="*"/>

        <site-control permitted-cross-domain-policies="all"/>

</cross-domain-policy>

Could it be a content-type restriction?  How can I allow all content types if so?