Jump to content
GreenSock

Ahrengot

Weird stuff happens when i load through a php proxy

Recommended Posts

Hey jack,

 

Just a heads up. When i load xml feeds through a php proxy. i.e. "domain.com/php/proxy.php?url=http://whatever/feed" with the XML loader it will successfully call the onComplete method, but the content is an empty string. I know the proxy works and it has nothing to do with crossdomain pains because it works when i simply load the same url through the native URLLoader class.

 

It doesn't matter wether i send the url to XMLLoader wrapped in a URLRequest or not.

 

Is this a bug that you're aware of, if so, is there a workaround other than using URLLoader?

 

I've uploaded a simple example. I've also provided the php code i use in my proxy file.

Link to comment
Share on other sites

Hmm...are you sure your proxy is working? I just hit it through my browser and got nothing returned and I also tried to verify what you were saying about a plain URLLoader working fine, but it gave me exactly the same result as XMLLoader (blank). What am I missing?

Link to comment
Share on other sites

Hmm...are you sure your proxy is working? I just hit it through my browser and got nothing returned and I also tried to verify what you were saying about a plain URLLoader working fine, but it gave me exactly the same result as XMLLoader (blank). What am I missing?

 

I was experimenting with something in the proxy yesterday that broke it for about 20 minutes, we might be unlucky enough that you tested it in that excact time period, because it should be working. I've uploaded a new one just for this forum post, so i won't touch it, i promise ;) - It's an exact copy of the proxy from when I posted the bug yesterday: http://openminded.dk/php/proxy.php

 

if you send a url to the file via GET or POST you'll see it works just fine. At least it does when i query it like so: http://openminded.dk/php/proxy.php?url=http://blog.openminded.dk/api/read/

 

Please note that i've updated the example with the new proxy url - I've also added a URLLoader in the example which works as it should here on my machine (it traces out the blog feed of http://blog.openminded.dk/).

Link to comment
Share on other sites

It looks like the problem is that you're using a malformed URL - the query string after the "?" is not supposed to contain unencoded special characters. So why does the URLLoader work? Because it doesn't parse the URL at all, but LoaderMax MUST parse through it in order to avoid several nasty bugs in Adobe's URLRequest and URLLoader classes, some of which are listed at http://www.greensock.com/loadermax/#bugs. So overall, it's actually safer to use LoaderMax, but in this case you're seeing the strange behavior because of the malformed URL. If you don't want to adjust your PHP script to decode the encoded value properly (which you can encode using escape(_feedURL)), you can still use XMLLoader by passing in a URLRequest that has its method set to "post" and uses URLVariables like this:

 

var request:URLRequest = new URLRequest(_proxyURL);
request.method = "post";
request.data = new URLVariables();
request.data.url = _feedURL;
_loader = new XMLLoader(request, { onComplete:xmlLoaderComplete, onError:xmlLoaderError } );

Link to comment
Share on other sites

Cool, Jack, makes sense now that i know why — I was just surprised that the XMLLoader fired the onComplete callback as if everything was great even though the content was missing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×